You are on page 1of 2

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

Functions on a queue object

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

Difference between stacks and queues


In stacks we remove the item that is most recently added (LIFO)
In queues we remove the item that is least recently added (FIFO)
Initialisation of a queue
typedef struct queue
{
int a [size];
int front =0;
int rear = -1;
}

You might also like