A Queue Is
A Queue Is
Think
of a queue as people standing in line in a supermarket. The first
person to stand in line is also the first who can pay and leave
the supermarket. This way of organizing elements is called
FIFO: First In First Out.
Think of a queue as people standing in line in a supermarket.
The first person to stand in line is also the first who can pay and
leave the supermarket. This way of organizing elements is
called FIFO: First In First Out.
Basic operations we can do on a queue are:
Enqueue: Adds a new element to the queue.
Dequeue: Removes and returns the first (front) element from
the queue.
Peek: Returns the first element in the queue.
isEmpty: Checks if the queue is empty.
Size: Finds the number of elements in the queue.
Representation of Queues
Similar to the stack ADT, a queue ADT can also be implemented
using arrays, linked lists, or pointers. As a small example in this
tutorial, we implement queues using a one-dimensional array.
Queue Insertion Operation: Enqueue()
The enqueue() is a data manipulation operation that is used to insert
elements into the stack. The following algorithm describes the
enqueue() operation in a simpler way.
Algorithm
1. START
Algorithm