Queues
Queues
Concept of a queue
Definition:
A queue is a data structure consisting of an ordered collection of items into which new items
may be inserted at one end, called the REAR of the queue, and from which items may be
deleted at the other end, called the FRONT of the queue.
myQueue A B C D
front rear
Example of a queue
A line of students in a food court. New additions to the line are made to the back of the line,
while removal (or serving) happen in the front.
In the queue, only 2 operations are allowed -:
i) Enqueue is to insert an item into the back of the queue
ii)Dequeue is removing the front element in a queue
Function Effect
S iz e Returns the actual number of elements in
the queue
Empty Returns true if the queue is empty and
returns false otherwise
Push Inserts an element into the queue
Front It returns the first element in the queue but
does not remove the element from the queue
Back Returns the last element in the queue
Pop Removes an element in the queue