| Article Index |
|---|
| CIRCULAR QUEUE IMPLEMENTATION USING ADT |
| SOURCE CODE |
| DOCUMENTATION |
| TEST CASES AND COMPATIBILITY |
| All Pages |
GOAL OF THE CODE:
To implement a circular queue using ADT.
VARIABLES USED:
1.a-pointer variable which stores the contents of the queue.
2.rear-pointer variable which points to the location where insertion is done.
3.front-pointer variable which points to the location where deletion is done.
4.cap-variable which indicates the maximum no.of elements that the queue can hold.
5.size-variable which indicates the no.of elements present in the queue at a particular instant.
6.queue-pointer to the structure qrec.
7.max-variable which indicates the maximun no.of elements (to be entered by the user).
8.x-local variable which stores the element to be inserted(in enqueue()).
9.p- local variable which contains the front most element(returned by frontanddelete()).
10.i-counter variable used to display the contents of the queue(in display()).
IN MAIN() FUNCTION:
11.m-variable which indicates the maximun no.of elements (to be entered by the user).
12.b-variable which stores the choice(to be entered by the user).
13.c-variable used in almost all the case statements to store the respective values.
FUNCTIONS USED:
|
FUNCTIONS |
PURPOSE |
|
createqueue() |
Dynamically allocates memory for the queue. |
|
makempty() |
Initializes rear and front to -1. |
|
isfull() |
Returns 1 if the queue is full else returns 0. |
|
isempty() |
Returns 1 if the queue is empty else returns 0. |
|
enqueue() |
Inserts elements into the queue. |
|
dequeue() |
Deletes elements from the queue. |
|
front() |
Returns the front most element of the queue. |
|
frontanddelete() |
Deletes the front most element and then returns the value pointed out by the front pointer. |
|
display() |
Displays the contents of the queue. |
IMPLEMENTATION:
1.Initially,the maximum no.of elements to be stored in the queue is obtained from the user.
2.A circular queue is created by dynamically allocating memory using createqueue() function.
3.Then, choices are provided to the user from which one can choose the operation to be performed.
4.A switch case is made use of in this code. Depending upon the choice entered by the user,the corresponding operations are performed.
5.After each operation,the display() function is called so that the user can better understand the implementation.
6.If the user enters a number that has not been specified in the cases, the default case is executed and the program terminates.
Initialization Conditions:
1.front and rear are initialised to -1.
2.size is initialised to 0.
3.capacity is assigned with the max. no.of elements.
| < Prev | Next > |
|---|




