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

A Queue Is

Uploaded by

aamirshahad3321
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

A Queue Is

Uploaded by

aamirshahad3321
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

A queue is a data structure that can hold many elements.

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

2. Check if the queue is full.


3. If the queue is full, produce overflow error and exit.
4. If the queue is not full, increment rear pointer to point
the next empty space.
5. Add data element to the queue location, where the rear
is pointing.
6. return success.
7. END

Queue - The peek() Operation


The peek() is an operation which is used to retrieve the frontmost
element in the queue, without deleting it. This operation is used to
check the status of the queue with the help of the pointer.

Algorithm

You might also like