Queue Implementation in C++

This article is about queue implementation using array in C++.


Queue as an Abstract data Type

Queue is an ordered data structure to store datatypes in FIFO (First in First Out) order. That means the element which enters first is first to exit(processed). It’s like the normal queue in front of any ticket counter. Of course, the first person would be the first to get his ticket from the counter. Queue is a similar data type where insertion and deletion are done at two opposite ends, namely front and rear. Queue only hold similar datatypes.

The insertion process is named as enQueue

The deletion process is named as deQueue

EnQueue at the rear end

DeQueue at the front end


Operation on Queue

Type_t =any datatype

Basic operations:

enQueue(Type_t data): It inserts data of datatype Type_t to the queue

Type_t deQueue(): Removes the first element(at front end) from queue and returns it

Other operations:

Type_t queue_front(): Returns front element

bool isEmpty(): returns true if queue is empty, else returns false

int size(): Returns size of the queue

Example:

Let the elements inserted are

1, 2, 3, 4

QueueImplementationUsingCpp


C++ implementation

Output:
<div class="content-box-yellow”>
press 1 for enQueue()

press 2 for deQueue()

press 3 for front()

press 4 for size()

press 0 for exit

press your choice

1

Enter element

1

1 is enQueued

press your choice

2

Dequeued element: 1

press your choice

2

Empty Queue

press your choice

1

Enter element

2

2 is enQueued

press your choice

1

Enter element

3

3 is enQueued

press your choice

3

Front element: 3

press your choice

4

Size is: 2

press your choice

5

Invalid number, try again!

press your choice

0

Exiting…

That’s about Queue Implementation in C++

Was this post helpful?

Leave a Reply

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