Beruflich Dokumente
Kultur Dokumente
CHAPTER 1
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
FUNDAMENTALS OF C++
2
3
4
4
6
7
8
10
10
10
10
11
13
13
13
14
14
14
15
16
17
18
18
19
19
20
20
21
22
22
24
26
26
26
28
28
1.9
1.10
1.11
1.12
1.13
1.14
1.15
1.16
1.17
1.18
1.19
1.20
1.21
1.22
1.23
1.24
1.25
1.26
1.27
1.28
29
29
30
33
34
34
35
36
37
38
40
41
42
44
46
48
48
49
50
52
53
53
55
57
57
58
62
64
65
66
67
69
69
70
70
72
72
73
73
75
75
76
78
78
1.29
1.30
1.31
1.32
1.33
1.34
1.35
1.36
1.37
CHAPTER 2
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.10
2.11
2.12
2.13
79
79
82
83
83
85
86
89
89
91
92
93
94
95
Inheritance...........................................................................................
2.1.1 Defining Derived Classes.......................................................
Types Of Inheritance...........................................................................
2.2.1 Depending Upon The Access Specifiers................................
2.2.2 Depending Upon The Level of Derivation.............................
Single Inheritance................................................................................
Multiple Inheritance............................................................................
Multilevel Inheritance.........................................................................
Hierarchical Inheritance......................................................................
Hybrid Inheritance...............................................................................
Multi Path Inheritance.........................................................................
Base, Derived Class Constructors & Destructors................................
Inline Functions...................................................................................
2.10.1 Automatic Inlining.................................................................
2.10.2 Default Arguments.................................................................
Friends ...............................................................................................
2.11.1 Friend Classes........................................................................
2.11.2 Friend Functions....................................................................
2.11.3 Non-member Friend Functions..............................................
Virtual Functions.................................................................................
2.12.1 Pure Virtual Functions...........................................................
2.12.2 Virtual Destructors.................................................................
The this Pointer...................................................................................
2
2
3
3
6
7
9
12
14
17
20
21
23
24
25
26
26
27
29
30
33
33
35
2.14
2.15
2.16
2.17
2.18
2.19
2.20
CHAPTER 3
3.1
3.2
3.3
3.4
36
38
38
40
40
40
42
42
43
44
45
46
47
48
48
49
49
49
53
54
55
55
57
59
60
60
62
64
65
66
Introduction.........................................................................................
Single Dimensional Arrays..................................................................
3.2.1 Declaring Arrays....................................................................
3.2.2 Accessing Array Elements.....................................................
3.2.3 Initializing Single Dimensional Arrays..................................
Double Dimensional Arrays................................................................
3.3.1 Initializing Double Dimensional Arrays.................................
Multidimensional Arrays.....................................................................
3.2
3.2
3.3
3.3
3.5
3.7
3.8
3.10
3.5
3.6
3.7
3.8
3.9
3.10
3.11
3.12
3.13
3.14
3.15
3.16
3.17
3.18
3.19
3.20
3.21
Strings ..................................................................................................
3.5.1 Declaring Strings....................................................................
3.5.2 Initializing Strings..................................................................
3.5.3 Reading Strings......................................................................
String Library Functions.....................................................................
Pointers .......................................................................................3.15
3.7.1 Pointer Operators.................................................................
3.7.2 Initialization of Pointers.........................................................
3.7.3 Pointer Arithmetic..................................................................
Pointers and Arrays.............................................................................
Array of Pointers.................................................................................
Pointer to Functions............................................................................
Pointer to Pointers...............................................................................
Passing Values to Functions................................................................
3.12.1 Call by Value.........................................................................
3.12.2 Call by Reference Using a Pointer ........................................
3.12.3 Call by Reference Using a Reference Parameter....................
Passing Arrays to Functions................................................................
3.13.1 Passing Array Elements to a Function....................................
3.13.2 Passing Entire Array to a Function.........................................
Pointer Declarations..........................................................................
Structures............................................................................................
3.15.1 Declaring a Structure............................................................
3.15.2 Defining a Structure.............................................................
3.15.3 Accessing Structure Members..............................................
3.15.4 Initializing a Structure..........................................................
Nested Structures.................................................................................
Array of Structures..............................................................................
Structures and Functions.....................................................................
3.18.1 Passing a Structure Member to Functions............................
3.18.2 Passing The Address of Members to Functions....................
3.18.3 Passing Entire Structure to Functions...................................
Structures and Pointers......................................................................
Bit Fields.............................................................................................
Unions ..................................................................................................
3.21.1 Initializing a Union..............................................................
Summary
Review Questions
3.11
3.11
3.11
3.12
3.14
3.15
3.16
3.17
3.17
3.19
3.20
3.21
3.22
3.22
3.23
3.24
3.25
3.25
3.25
3.26
3.29
3.29
3.30
3.31
3.32
3.33
3.36
3.38
3.38
3.38
3.39
3.40
3.41
3.42
3.43
CHAPTER 4
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.7.3
4.8
4.9
LINKED LISTS
Introduction......................................................................................................
4.1.1
Primary Data Structures....................................................................
4.1.2
Secondary Data Structures................................................................
Abstract Data type...........................................................................................
The List ADT
.............................................................................................
4.3.1
List Operations..................................................................................
4.3.2
Array Implementation of Lists..........................................................
Basic Operations in a Linear List using Arrays...............................................
4.4.1
Creation of a New List......................................................................
4.4.2
Insertion of a Node............................................................................
4.4.3
Modification of a Node.....................................................................
4.4.4
Deletion of a Node............................................................................
4.4.5
Traversel of a List.............................................................................
Linked Lists Implementation of Lists..............................................................
4.5.1
Types of Linked Lists.......................................................................
4.5.1.1 Singly Linked List.............................................................
4.5.1.2 Doubly Linked List...........................................................
4.5.1.3 Circular Linked List..........................................................
Basic Operations in a Singly Linked List........................................................
4.6.1
Creation of a New List......................................................................
4.6.2
Insertion of a Node............................................................................
4.6.3
Modification of a Node.....................................................................
4.6.4
Deletion of a Node............................................................................
4.6.5
Traversal of a List.............................................................................
Basic Operations in Doubly Linked List.........................................................
4.7.1
Creation of a New List
4.7.2
Insertion of a Node
Modification of a Node....................................................................................
4.7.4
Deletion of a Node............................................................................
4.7.5
Traversal of a List.............................................................................
Basic Operations in a Circular Singly Linked List..........................................
4.8.1
Creation of a New List......................................................................
4.8.2
Insertion of a Node............................................................................
4.8.3
Modification of a Node.....................................................................
4.8.4
Deletion of a Node............................................................................
4.8.5
Traversal of a List.............................................................................
Basic Operations in Circular Doubly Linked List...........................................
4.9.1
Creation of a New List......................................................................
4.9.2
Insertion of a Node............................................................................
4.9.3
Modification of a Node.....................................................................
4.9.4
Deletion of a Node............................................................................
4.9.5
Traversal of a List.............................................................................
4.2
4.2
4.2
4.4
4.5
4.5
4.6
4.6
4.7
4.7
4.9
4.10
4.12
4.20
4.21
4.21
4.21
4.21
4.22
4.22
4.24
4.27
4.28
4.31
4.41
4.41
4.42
4.46
4.47
4.50
4.60
4.60
4.61
4.65
4.65
4.69
4.80
4.80
4.81
4.85
4.86
4.89
4.10
4.11
4.101
4.102
4.102
4.113
4.113
Summary
Review Questions
CHAPTER 5
5.1
5.2
5.3
5.3.6
5.4
5.5
5.6
STACKS
Introduction.........................................................................................
Representation of Stacks Using Arrays...............................................
5.2.1 Push Operation.......................................................................
5.2.2 Pop Operation........................................................................
5.2.3 Peek Operation .................................................................
5.2.4 Empty Stack...........................................................................
5.2.5 Fully Occupied Stack.............................................................
5.2.6 Traversing a Stack..................................................................
Representation of Stacks Using Linked Lists......................................
5.3.1 Push Operation.......................................................................
5.3.2 Pop Operation........................................................................
5.3.3 Peek Operation.......................................................................
5.3.4 Traversing a Stack..................................................................
5.3.5
Empty Stack
Fully Occupied Stack..........................................................................
5.3.7 Stack Size...............................................................................
Applications of Stacks.........................................................................
5.4.1 Towers of Hanoi.....................................................................
5.4.2 Reversing a String..................................................................
5.4.3 Balanced Paranthesis..............................................................
Recursion with Stacks.........................................................................
Evaluation of Arithmetic Expressions.................................................
5.6.1 Conversions of Notations.......................................................
5.6.2 Converting Infix Expression to Postfix Form.........................
5.6.3 Evaluating an Expression In Postfix Notation........................
Summary
Review Questions
5.2
5.2
5.2
5.4
5.4
5.5
5.5
5.6
5.11
5.11
5.12
5.13
5.14
5.14
5.15
5.15
5.21
5.21
5.23
5.24
5.28
5.29
5.31
5.36
5.40
CHAPTER 6
6.1
6.2
6.3
6.4
6.5
6.6
6.7
QUEUES
Introduction.........................................................................................
Types of Queues..................................................................................
6.2.1 Linear Queues........................................................................
6.2.2 Circular Queues......................................................................
6.2.3 Deques .............................................................................
Representation Of Linear Queues Using Arrays..................................
6.3.1 Enqueue Operation.................................................................
6.3.2 Dequeue Operation.................................................................
6.3.3 Peek Operation.......................................................................
6.3.4 Empty Queue.........................................................................
6.3.5 Fully Occupied Queue............................................................
6.3.6 Traversal of a Queue..............................................................
Representation of Queues Using Linked Lists.....................................
6.4.1 Enqueue Operation.................................................................
6.4.2 Dequeue Operation.................................................................
6.4.3 Peek Operation.......................................................................
6.4.4 Empty Queue.........................................................................
6.4.5 Fully Occupied Queue............................................................
6.4.6 Traversal of a Queue..............................................................
Representation of Circular Queues Using Arrays................................
6.5.1 Enqueue Operation.................................................................
6.5.2 Dequeue Operation.................................................................
6.5.3 Peek Operation.......................................................................
6.5.4 Empty Queue.........................................................................
Representation of Linear Deques Using Arrays..................................
6.6.1 Enqueue At Front Operation..................................................
6.6.2 Enqueue At Rear Operation...................................................
6.6.3 Dequeue At Front Operation..................................................
6.6.4 Dequeue At Rear Operation...................................................
6.6.5 Value At Front Operation.......................................................
6.6.6 Value At Rear Operation........................................................
6.6.8 Fully Occupied Deque............................................................
6.6.9 Traversal of a Queue..............................................................
Representation of Circular Deques Using Arrays................................
6.7.1 Enqueue At Front Operation..................................................
6.7.2 Enqueue At Rear Operation...................................................
6.7.3 Dequeue At Front Operation .................................................
6.7.4 Dequeue At Rear Operation...................................................
6.7.5 Value At Front Operation.......................................................
6.7.6 Value At Rear Operation........................................................
6.7.7 Empty Deque.........................................................................
6.2
6.3
6.3
6.3
6.4
6.5
6.6
6.6
6.7
6.7
6.8
6.8
6.14
6.14
6.15
6.17
6.17
6.18
6.18
6.24
6.24
6.24
6.25
6.26
6.32
6.32
6.33
6.34
6.34
6.35
6.35
6.36
6.37
6.45
6.45
6.46
6.47
6.48
6.48
6.49
6.49
6.8
6.9
6.10
6.49
6.50
6.58
6.59
6.59
6.60
6.61
6.61
6.62
6.62
6.63
6.71
6.71
6.72
6.73
6.74
6.74
6.75
Summary
Review Questions
CHAPTER 7
7.1
7.2
7.3
7.4
7.5
7.6
7.7
TREES
Introduction.........................................................................................
Binary Trees........................................................................................
7.2.1 Types of Binary Trees............................................................
Representation of Binary Trees...........................................................
7.3.1 Linear Representation of Binary Trees ..............................
7.3.2 Linked Representation of Binary Trees..................................
Binary Tree Traversal..........................................................................
7.4.1 Preorder Traversal..................................................................
7.4.2 Inorder Traversal....................................................................
7.4.3 Postorder Traversal................................................................
7.4.4 Level Order Traversal............................................................
Conversion of General Trees to Binary Trees.....................................
Binary Search Trees............................................................................
Basic Operations in a Binary Search Tree...........................................
7.7.1 Creation of a Binary Search Tree...........................................
7.7.2 Creation of a node..................................................................
7.7.3 Deletion of a Node.................................................................
7.2
7.3
7.4
7.5
7.5
7.6
7.7
7.7
7.8
7.8
7.8
7.18
7.19
7.19
7.19
7.20
7.21
7.8
7.9
7.10
7.11
CHAPTER 8
8.1
8.2
8.3
8.4
8.5
8.6
8.7
8.8
7.23
7.23
7.32
7.32
7.32
7.33
7.33
7.35
7.35
7.35
7.48
7.48
7.49
7.49
7.51
GRAPHS
Introduction......................................................................................... 8.2
8.1.1
Definition in Graphs ............................................................ 8.2
Graph Representation and its Operations............................................ 8.4
8.2.1
Incidence Matrix.................................................................. 8.4
8.2.2
Adjacency Matrix................................................................. 8.7
8.2.3
Adjacency List .................................................................8.14
Path Matrix.......................................................................................... 8.22
8.3.1.
From Powers Of Path Matrix............................................... 8.23
8.3.2.
Transitive Closure / Warshalls Algorithm........................... 8.29
8.3.3
Modified Warshalls Algorithm........................................... 8.34
Graph Traversals................................................................................. 8.37
8.4.1
Depth First Traversal............................................................ 8.37
8.4.2
Breadth First Traversal......................................................... 8.39
Application of DFS - Topological Sorting........................................... 8.41
Shortest Path Algorithm - Dijkstras Algorithm.................................. 8.45
Minimum Spanning Trees .................................................................. 8.49
8.7.1
Prims Algorithm................................................................. 8.49
8.7.2
Kruskals Algorithm ............................................................ 8.54
Applications of Graphs...................................................................... 8.58
8.8.1
Bi - Connectivity in Graphs................................................. 8.58
8.8.2
Euler Circuits....................................................................... 8.60
8.8.3
Hamilton Circuits................................................................. 8.60
Summary
Review Questions
CHAPTER 9
9.1
9.2
9.3
9.4
9.5
9.6
9.7
9.8
9.9
9.10
9.11
9.12
Introduction.........................................................................................
Bubble Sort.........................................................................................
Insertion Sort .....................................................................................
Selection Sort......................................................................................
Shell Sort.............................................................................................
Quick Sort....................................................................................9.11
Merge Sort...........................................................................................
Radix Sort...........................................................................................
Heap Sort ...........................................................................................
External Sorting..................................................................................
Linear Search......................................................................................
Indexed Sequential search...................................................................
9.13
9.14
CHAPTER 10
10.1
10.2
10.3
10.4
10.5
10.6
9.2
9.3
9.5
9.7
9.9
9.14
9.17
9.19
9.23
9.28
9.29
10.7
10.8
10.9
10.10
10.11
10.12
SELF-REVIEW EXERCISES
APPENDIX
1.
2.
3.
4.
5.
6.
7.
8.
9.
A.2
A.3
A.4
A.8
A15
A17
A.18
A.25
s