Sie sind auf Seite 1von 12

CONTENTS

CHAPTER 1
1.1

1.2

1.3

1.4

1.5
1.6
1.7

1.8

FUNDAMENTALS OF C++

History Of C & C++............................................................................


1.1.1 Steps In Learning C++...........................................................
1.1.2 The C++ Character Set...........................................................
1.1.3 Tokens, Identifiers & Keywords............................................
Data Types .........................................................................................
1.2.1 Primary Data Types................................................................
1.2.2 User-defined Data Types........................................................
1.2.3 C++ Data Types ....................................................................
1.2.4 Empty Data Type...................................................................
Constants.............................................................................................
1.3.1 Integer Constants....................................................................
1.3.2 Real Constants.......................................................................
1.3.3 Single Character Constants ...................................................
1.3.4 Wide Character Constants......................................................
1.3.5 String Constants.....................................................................
Variables.............................................................................................
1.4.1 Declaration of Variables.........................................................
1.4.2 Initialization of Variables.......................................................
Arrays ..... ...........................................................................................
Escape Sequences................................................................................
Operators.............................................................................................
1.7.1 Arithmetic Operators..............................................................
1.7.2 Unary Operators.....................................................................
1.7.2.1 The sizeof Operator.................................................
1.7.3 Relational Operators...............................................................
1.7.4 Equality Operators.................................................................
1.7.5 Logical Operators...................................................................
1.7.6 Bitwise Operators...................................................................
1.7.7 Conditional Operator..............................................................
1.7.8 Assignment Operators............................................................
1.7.9 Special Operators...................................................................
1.7.10 C++ Operators .......................................................................
Statements...........................................................................................
1.8.1 Expression Statements...........................................................
1.8.2 Compound Statements...........................................................
1.8.3 Control Statements.................................................................

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

1.8.4 Jump Statements....................................................................


Library Functions & Header Files.......................................................
Structure of a C+ + Program..............................................................
The main() Function............................................................................
Input & Output in C+ +.......................................................................
1.12.1 Standard Input Stream Using cin............................................
1.12.2 Standard Output Stream Using cout.......................................
Declaration of Variables in C++..........................................................
1.13.1 Scope of Variables.................................................................
Control Statements..............................................................................
1.14.2 The If-else Statement.............................................................
1.14.3 Multiple If-else Statements....................................................
1.14.4 Nested If-else Statements.......................................................
1.14.5 The switch Statement.............................................................
The Conditional Operator....................................................................
Looping Statements.............................................................................
1.16.1 The while Loop.....................................................................
1.16.2 The do-while Loop................................................................
1.16.3 The for Loop.........................................................................
The break Statement............................................................................
The continue Statement.......................................................................
The goto Statement..............................................................................
OOP Concepts.....................................................................................
Class .....................................................................................................
1.21.1 Definition Of a Class..............................................................
1.21.2 Class Members.......................................................................
The Scope Resolution Operator...........................................................
Constructors........................................................................................
1.23.1 Parameterized Constructors....................................................
1.23.2 Default Constructor................................................................
1.23.3 Copy Constructor...................................................................
1.23.4 Overloaded Constructors........................................................
Destructors..........................................................................................
1.24.1 Order Of Constructor & Destructor Calls...............................
Free Store Operators - new & delete...................................................
The const Keyword.............................................................................
1.26.1 The const Variables & Pointers..............................................
1.26.2 The const Arguments.............................................................
1.26.3 The const Member Functions.................................................
Static Class Members..........................................................................
1.27.1 Static Data Members..............................................................
1.27.2 Static Member Functions.......................................................
Function Overloading.........................................................................
1.28.1 Overloading Functions With Different Types of Arguments..

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

1.28.2 Overloading Functions With Different Number of Arguments


1.28.3 Overloading Functions With Different Sequence of Arguments
Operator Overloading..........................................................................
Overloading Unary Operators Using Member Functions....................
1.30.1 Overloading Increment & Decrement Operators....................
1.30.2 Overloading Unary Minus Operator.......................................
Overloading Unary Operators Using Friend Functions.......................
Overloading Binary Operators Using Member Functions...................
1.32.1 Overloading Plus Operator.....................................................
Overloading Binary Operators Using Friend Functions......................
Overloading The Function Call Operator............................................
Overloading The Subscript Operator...................................................
Overloading Relational And Logical Operators..................................
Overloading The Member Access Operator........................................
Summary
Review Questions

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

ADVANCED CONCEPTS OF C++

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

Files & Streams...................................................................................


Operations In a File.............................................................................
2.15.1 The open() Function...............................................................
2.15.2 The close() Function..............................................................
2.15.3 Writing Text In Files..............................................................
2.15.4 Reading Text In Files.............................................................
2.15.5 Appending Text In Files.........................................................
2.15.6 Detecting End Of Files...........................................................
2.15.7 The put() & get() Functions....................................................
2.15.8 The read() & write() Functions...............................................
2.15.9 The getline() Function............................................................
Random Access In Files......................................................................
2.16.1 The seekg() Function..............................................................
2.16.2 The seekp() Function..............................................................
2.16.2 The seekp() Function..............................................................
2.16.3 The tellg() & tellp() Functions...............................................
Formatting I/O Streams.......................................................................
2.17.1 Formatting Using ios Member Functions...............................
2.17.2 Formatting Using Manipulators.............................................
2.17.3 Formatting Using User-defined Manipulators........................
Standard Template Library
........................................................
2.18.1 Function Templates................................................................
2.18.2 Class Templates ....................................................................
Exceptions...........................................................................................
2.19.1 The try Block.........................................................................
2.19.2 The catch Block.....................................................................
2.19.3 Rethrowing an Exception.......................................................
Namespaces.........................................................................................
2.20.1 Using Namespace...................................................................
2.20.2 Namespace Std.......................................................................
Summary
Review Questions

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

ARRAYS, POINTERS, STRUCTURES & UNIONS

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

Cursor Linked Lists.........................................................................................


4.10.1
Memory Allocation in Cursor Linked List.....................................
4.10.2
Memory DEallocation in Cursor Linked List.................................
Applications of Linked Lists............................................................................
4.11.1
Polynomial Manipulation...............................................................

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.7.8 Fully Occupied Deque............................................................


6.7.9 Traversal of a Queue..............................................................
Application of Queues.........................................................................
Representation of Priority Queue Using Arrays..................................
6.9.1 Creation of a Priority Queue..................................................
6.9.2 Enqueue Operation.................................................................
6.9.3 Dequeue Operation.................................................................
6.9.4 Peek Operation.......................................................................
6.9.5 Empty Priority Queue............................................................
6.9.6 Fully Occupied Queue............................................................
6.9.7 Traversal of a Priority Queue.................................................
Representation Of Priority Queue Using Linked Lists........................
6.10.1 Creation of a Priority Queue..................................................
6.10.2 Enqueue Operation.................................................................
6.10.3 Dequeue Operation.................................................................
6.10.4 Peek Operation.......................................................................
6.10.5 Empty Priority Queue............................................................
6.10.6 Traversal of a Priority Queue.................................................

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

7.7.4 Modification of a Node..........................................................


7.7.5 View The Contents of The Binary Search Tree......................
Threaded Binary Trees........................................................................
Basic Operations in a Threaded Binary Tree.......................................
7.9.1 Creation of a Threaded Binary Tree.......................................
7.9.2 Insertion of a Node.................................................................
7.9.3 Deletion of a Node.................................................................
7.9.4 Searching a Node...................................................................
7.9.5 Modification of a Node..........................................................
7.9.6 View The Contents of The Threaded Binary Tree..................
AVL Trees...........................................................................................
Basic Operations in an AVL Tree.......................................................
7.11.1 Inserting a Node in an AVL Tree...........................................
7.11.2 Types of Rotation in an AVL Tree.........................................
7.11.3 Deleting a Node From an AVL Tree......................................
Summary
Review Questions

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

SORTING & SEARCHING

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

Binary Search...................................................................................... 9.31

9.14

Fibonacci Search................................................................................. 9.33


Summary
Review Questions

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

HASHING, HEAPS, SETS & ALGORITHMS

Hashing ............................................................................................. 10.2


10.1.1 Trunction Method................................................................ 10.3
10.1.2 Folding Method.................................................................... 10.4
10.1.3 MID - Square Method.......................................................... 10.4
10.1.4 Division Method.................................................................. 10.4
Collision Resolution Technique - Open Addressing............................ 10.5
10.2.1 Linear Probing..................................................................... 10.5
10.2.2 Quadratic Probing................................................................ 10.6
Collision Resolution Technique - Seperate Chaining.......................... 10.7
Binary Heaps....................................................................................... 10.8
The Set & Disjoint Set ADT............................................................... 10.9
Dynamic Equivalence Problem........................................................... 10.11

10.7
10.8
10.9
10.10

10.11
10.12

Smart Union Algorithms..................................................................... 10.11


Path Compression................................................................................ 10.13
Algorithms.......................................................................................... 10.14
10.9.1 Types Of Control Flow........................................................ 10.15
Efficiency Of An Algorithm................................................................ 10.19
10.10.1 Time Complexity................................................................. 10.19
10.10.2 Space Complexity................................................................ 10.20
Asymptotic Notations.......................................................................... 10.20
Algorithmic Paradigms........................................................................ 10.21
10.12.1 Divide And Conquer Algorithm........................................... 10.21
10.12.2 Dynamic Programming........................................................ 10.26
10.12.3 Greedy Algorithm................................................................ 10.30
Summary
Review Questions

SELF-REVIEW EXERCISES
APPENDIX
1.
2.
3.
4.
5.
6.
7.
8.
9.

ASCII Table .......................................................................................


Precedence Table ................................................................................
Header Files .......................................................................................
Library Functions ...............................................................................
The iostream Library...........................................................................
The iomanip Library............................................................................
Common Programming Errors............................................................
Keys used in C++ Compiler ...............................................................
Glossary..............................................................................................

A.2
A.3
A.4
A.8
A15
A17
A.18
A.25
s

Das könnte Ihnen auch gefallen