| Article Index |
|---|
| CIRCULAR QUEUE IMPLEMENTATION USING LINKED LIST |
| SOURCE CODE |
| DOCUMENTATION |
| TEST CASE AND COMPATIBILITY |
| All Pages |
IMPLEMENTATION OF A CIRCULAR QUEUE USING
LINKED LIST
INTRODUCTION:
We know that a linear queue is a “first in first out “ data structure,i.e., insertion can be made only at the end and deletion can be made only at the front. In a linear queue, the traversal through the queue is possible only once,i.e.,once an element is deleted,we cannot insert another element in its position.
This disadvantage of a linear queue is overcome by a circular queue, thus saving memory. In a circular queue, after rear reaches the end of the queue, it can be reset to zero. This helps in refilling the empty spaces in between.
A linked list is a data structure that consists of a sequence of nodes. Each node consists of two fields-information and address. The information part contains the value that the node holds. The address part contains the address of the next node. The last node contains NULL in the address part.
NODE 1 NODE 2 NODE 3

In a linked list, the nodes are logically connected but they may not be physically adjacent. This makes lists more advantageous than arrays where the data must be physically adjacent and at the same time logically connected. Here, nodes can be inserted and deleted at any point in the list unlike stacks, queues. But it is possible to implement a circular queue using a linked list.
CODE:
GOAL OF THE CODE:
To implement a circular queue using LINKED LIST.
VARIABLES USED:
FUNCTIONS USED:
-
FUNCTION
PURPOSE
createqueue()
Dynamically allocates memory for the queue.
displayq()
Displays the contents of the queue.
isempty()
Returns 1 if the queue is empty else returns 0.
insert()
Inserts elements into the queue.
delete()
Deletes elements from the queue.
front()
Returns the front most element of the queue.
frontdel()
Deletes the front most element and then returns the value pointed out by the front pointer.
IMPLEMENTAION:
-
Initially,the maximum no.of elements to be stored in the queue is obtained from the user.
-
A circular queue is created by dynamically allocating memory using createqueue() function.
-
Then, choices are provided to the user from which one can choose the operation to be performed.
-
A switch case is made use of in this code. Depending upon the choice entered by the user,the corresponding operations are performed.
-
After each operation,the display() function is called so that the user can better understand the implementation.
-
If the user enters a number that has not been specified in the cases, the default case is executed and the program terminates.
Initialization: Assign the address of the header node to the address part of the next node(also known as emptying the queue).
TEST CASE:
The choices are
1.Insert
2.Delete
3.Front
4.Frontdelete
5.Exit
Enter your choice:1
Enter the element:5
The contents of the queue are:
5
Enter your choice:1
Enter the element:7
The contents of the queue are:
5 7
Enter your choice:1
Enter the element:8
The contents of the queue are:
5 7 8
Enter your choice:2
Element deleted
The contents of the queue are:
7 8
Enter your choice:3
Front value is 7
The contents of the queue are:
7 8
Enter your choice:4
Deleted element is 7
The contents of the queue are:
8
Enter your choice:5
COMPATIBILITY:
Compatible with all computers which are capable of running gcc-4.3.3-5. The program has been tested with the above version of gcc as of june 12.
| < Prev | Next > |
|---|




