Data Structure: Implementation of Queue in C++

A queue is an order collection of items from which items may be deleted at one end (called front or head of the queue) and into which items may be inserted at the other end (called the rear end or tail of the queue). It is First-in-First-out (FIFO) type of data structure. Operations on the queue are: Create a Queue, insert items, remove items, display etc.
Please refer to this link for a more detailed explanation of queue and its implementation in C, C++, Python, and Java.
Algorithm for Implementation of Queue in C++
1. Declare and initialize neccessary variables, front = 0, rear = -1 etc.
2. For enque operation,
If rear >= MAXSIZE – 1
print “Queue is full”
– Increment rear by 1 i.e. rear = rear + 1;
– queue[rear] = item;
3. For next enqueue operation, goto step 2.
4. For dequeue operation
If front > rear
print “Queue is Empty”
– item = queue[front]
– increment front by 1 i.e. front = front + 1
5. For dequeue next data items, goto step 4.
6. Stop

Source Code:

SHARE Data Structure: Implementation of Queue in C++

You may also like...

5 Responses

  1. Anonymous says:

    this program is not excuteable on the quincy

  2. Anonymous says:

    (Used the given source code)
    After I enqueued data, I dequeued and then enqueued a new one. Then select Display all elements. The last data dequeued was added at the bottom of the list. Is this an error on the code?
    I'm new to programming.

  3. Thank you you make my work even better. This program is worthy.

Leave a Reply

Your email address will not be published. Required fields are marked *