Eee DS (Unit 3)
Eee DS (Unit 3)
Syllabus:
Linked Lists: Introduction, Single Linked Lists, Circular Linked Lists, Doubly Linked Lists, Multiple linked
lists, Applications
Linked Stacks and Linked Queues: Introduction, Operations on linked stacks and linked queues, Dynamic
memory management, Implementation of linked representations, Applications.
NOTE
In a single linked list, the address of the first node is always stored in a reference node known
as "front" (Some times it is also known as "head").
Always next part (reference part) of the last node must be NULL.
Example
Operations
In a single linked list we perform the following operations...
1. Insertion
2. Deletion
3. Display
Node Representation:
Operations
In a circular linked list, we perform the following operations...
1. Insertion
2. Deletion
3. Display
Before we implement actual operations, first we need to setup empty list. First perform the following steps
before implementing actual operations.
Step 1: Include all the header files which are used in the program.
Step 2: Declare all the user defined functions.
Step 3: Define a Node structure with two members data and next
Step 4: Define a Node pointer 'head' and set it to NULL.
Step 4: Implement the main method by displaying operations menu and make suitable function
calls in the main method to perform user selected operation.
Insertion
In a circular linked list, the insertion operation can be performed in three ways. They are as follows...
1. Inserting At Beginning of the list
2. Inserting At End of the list
3. Inserting At Specific location in the list
Inserting At Beginning of the list
We can use the following steps to insert a new node at beginning of the circular linked list...
Step 1: Create a newNode with given value.
Step 2: Check whether list is Empty (head == NULL)
Step 3: If it is Empty then, set head = newNode and newNode→next =head .
Step 4: If it is Not Empty then, define a Node pointer 'temp' and initialize with 'head'.
Step 5: Keep moving the 'temp' to its next node until it reaches to the last node (until 'temp →
next == head').
Step 6: Set 'newNode → next =head', 'head = newNode' and 'temp → next= head'.
Inserting At End of the list
We can use the following steps to insert a new node at end of the circular linked list...
Step 1: Create a newNode with given value.
Step 2: Check whether list is Empty (head == NULL).
Step 3: If it is Empty then, set head = newNode and newNode → next =head.
Step 4: If it is Not Empty then, define a node pointer temp and initialize with head.
Step 5: Keep moving the temp to its next node until it reaches to the last node in the list
(until temp → next == head).
Step 6: Set temp → next = newNode and newNode → next = head.
Circular header linked list which stores the address of the header node in the next field of the last
node. Here, the header node will denote the end of the list.