Advert

Singly Linked List

Last edited by . Total of no comments in the discussion.

In a singly (one-way) linear linked list, each node is divided into two parts. The first part contains the information of the element. The second part called the linked field or next pointer field contains the address of the next node in the list. A head pointer is used to hold the address of the first element in the list. Also, the last element of the linked list has a NULL value in the next pointer field to mark the end of the list. Declaration of a Linear Linked List Read More

Share on:

Binary Tree – Deleting a Node

Last edited by . Total of 2 comments in the discussion.

The possibilities which may arise during deleting a node from a binary tree are as follows: Node is a terminal node: In this case, if the node is a left child of its parent, then the left pointer of its parent is set to NULL. Otherwise if the node is a right child of its parent, then the right pointer of its parent is set to NULL Node has only one child: In this case, the appropriate pointer of its parent is set to child node. Node has two children: Read More

Share on:

Type Conversion – Class to Class

Last edited by . Total of no comments in the discussion.

Now that we have understood how to convert basic data types to class types and vice-versa, it is time to learn how to convert objects of one class type to another class type. The conversion between objects of different classes can be done using either a one-argument constructor or a conversion function. The choice depends upon whether the conversion routine has to be declared in the source class or in the destination class. To illustrate, consider a program that contains two classes: A and B. Also consider the statement: object_A Read More

Share on:

Breadth First Search Algorithm

Last edited by . Total of 1 comment in the discussion.

A breadth first search traversal method, visits all the successors of a visited node before visiting any successor of any of its child nodes. This is a contradiction to depth first traversal method; which visits the successor of a visited node before visiting any of its brothers, i.e., children of the same parent. A depth first traversal method tends to create very long, narrow trees; whereas breadth first traversal method tends to create very wide, short trees. Given an input graph G = (V, E) and source vertex s, from Read More

Share on:

Graphs

Last edited by . Total of no comments in the discussion.

A graph is an important non linear data structure. This data structure is used to represent relationship between pairs of elements, which may not, necessarily, be hierarchical in nature. A graph is defined as: “Graph G is an ordered set (V, E), where V(G) represents the set of elements, called vertices, and E(G) represents the edges between these vertices.” Graphs can be of either type, Undirected Graph Directed Graph Figures below show sample graphs. V(G) = { v1, v2, v3, v4, v5 } E(G) = { e1, e2, e3, e4, Read More

Share on:

break and continue Statements

Last edited by . Total of no comments in the discussion.

break Statement The break statement is used to alter the flow of control. When a break statement is executed in a while loop, for loop, do-while loop or switch statement, it causes immediate exit from that statement. Program execution continues with the next statement. Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch statement. The program written below demonstrates the break statement in a for-loop. When the if-statement detects that x has become 5, break statement is executed. Read More

Share on:

Constructors and Destructors

Last edited by . Total of no comments in the discussion.

A member function with the same name as its class is called a constructor. It is used to initialize the objects of that class-type with a some initial value. If a class has a constructor, each of the objects of that class will be initialized before they are used within the program. A constructor for a class is needed, so that the compiler automatically initializes an object as soon as it is created. A class constructor is defined without any return-type. They are called whenever a program creates an object Read More

Share on:

Overloading Binary Operators

Last edited by . Total of 1 comment in the discussion.

Binary operators can be overloaded in a similar manner as unary operators. We should note the following features of an operator function for a binary operator: It receives only one class type argument explicitly, in case of a member function. For a friend function, two class types are received as arguments. It returns a class type. Consider the following expression: C = A + B; The above expression contains three objects namely A, B and C of which A and B are the operands while C is the one to Read More

Share on:

Type Conversion

Last edited by . Total of no comments in the discussion.

It is often seen in programming that variables of different data types are used in the same expressions e.g. float with integer or an integer with a double. In these cases, C++ automatically converts one data type to another as the situation demands. The data type to the right of the assignment operator is converted to the type of data to the left. For example, when assigning an int to a float, the int will be promoted to a float and then assigned. The type conversions are automatic as long Read More

Share on:

Trees

Last edited by . Total of no comments in the discussion.

Arrays, linked lists, stacks and queues are used to represent linear and tabular data. These structures are not suitable for representing hierarchical data. In hierarchical data we have ancestors, descendants superiors, subordinates, etc Family Structure Business Corporate Structure Federal Government Structure Introduction to Trees Fundamental data storage structures used in programming Combine advantages of ordered arrays and linked lists Searching can be made as fast as in ordered arrays Insertion and deletion as fast as in linked lists Tree characteristics Consists of nodes connected by edges Nodes often represent entities Read More

Share on: