Queue

 

1 : Queue is an abstract data type or collection in which the entities in the collection are kept in order.
2 : Insertion/Enqueue takes place at rear end of the queue.
3 : Deletion/Dequeue takes place at front end of the queue.
4 : Queue works on the principle of FIFO(first in first out) which means the element which is inserted first can be deleted first.

Example : People standing in a queue to get movie ticket at the counter.The person who is first in the queue gets ticket first and leaves the queue first.

Figure :

Queue

 

Basic Operations in Queue:

Operation Description Complexity
enqueue(Object obj)  adds one element to the queue O(1)
dequeue()  deletes element from the queue O(1)
front() or peek()  returns the front or first element from queue O(1)
rear()  returns the rear or last element stack O(1)
size()  returns total  elements present in the queue O(1)
isEmpty()  checks if queue is empty O(1)
isFull()  checks if queue is full O(1)

Program class For  basic operation in Queue:

 

Problems :

1 : Implement stack using queue
 
 


Leave a comment

Your email address will not be published. Required fields are marked *

five × one =