Step 3 – Create a one-dimensional array with the above-defined SIZE (int queue).
Step 2 – Declare all the user-defined functions which are used in queue implementation.
Step 1 – Include all the header files which are used in the program and define a constant ‘SIZE’ with a specific value.
Step 4 − Add the data element to the queue location, where the rear is pointing.ĭata = queue front ← front + 1 return true.
Step 3 − If the queue is not full, increment the rear pointer to point to the next empty space.
Step 2 − If the queue is full, produce an overflow error and exit.
The following steps should be taken to enqueue (insert) data into a queue −
Therefore, its operations are comparatively difficult to implement than of stacks.
Queues maintain two data pointers, front and rear.
In case we maintain the queue in a circular linked list, the algorithm will differ.
As we are using single dimension array to implement queue, we just check for the rear pointer to reach at MAXSIZE to determine that the queue is full.
Implementation of peek() function in C programming language − The algorithm of peek() function is as follows − This function helps to see the data at the front of the queue. Let’s first learn about supportive functions of a queue − peek()