0% found this document useful (0 votes)
44 views

Queues

A queue is a data structure that follows the first-in, first-out (FIFO) principle. New items are added to the rear of the queue and items are removed from the front of the queue. Only two operations, enqueue and dequeue, are allowed on a queue - enqueue adds an item to the rear and dequeue removes an item from the front. Common queue functions include size, empty, push, front, back, and pop. Queues differ from stacks, which follow the last-in, first-out (LIFO) principle.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Queues

A queue is a data structure that follows the first-in, first-out (FIFO) principle. New items are added to the rear of the queue and items are removed from the front of the queue. Only two operations, enqueue and dequeue, are allowed on a queue - enqueue adds an item to the rear and dequeue removes an item from the front. Common queue functions include size, empty, push, front, back, and pop. Queues differ from stacks, which follow the last-in, first-out (LIFO) principle.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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