DS Study Material Module 1
DS Study Material Module 1
(Study infix to postfix conversion and postfix evaluation from note book)
7. Applications of stack
8. Explain Queue
a)A linear DS in which insertion and deletion can be done at TWO ENDS called REAR and
FRONT. Insertion at REAR end and deletion at FRONT end.
b)Queue is a First In First Out(FIFO) data structure, means the firsst inserted element
will be first deleted.
Traversal
PRIORITY QUEUE
a)Priority queue is a variation of simple queue
b)In Priority queue each element has a value associated with it called its priority.
c)When deletion operation is performed we remove the element with highest
priority.
d)In a priority queue the elements are stored in the ascending order of priority
value so that the element with highest priority will always be at the front position.
So elements are inserted into the queue in the order of priority.
CIRCULAR QUEUE
Consider the following case in a simple queue of maximum size 5.
Here Front points to the index 2 and rear points to 4 ie MAXSIZE-1. If we try to
insert a new element into the above queue, it will not be possible because
rear=MAXSIZE-1 eventhough two vacant positions are there at front. This is the
limitation of a simple queue. To avoid such limitation we can use circular queue.
In this queue the rear is incremented in such a way that after rear points to
MAXSIZE-1 it will point to 0 if that position is empty. In this case the queue
becomes full only if rear+1 points to front.
The pictorial representation of a circular queue is:
Now we can insert 4 more elements into the above queue. But in a simple queue
we can insert only 2 more elements.
After inserting three elements 30, 47 and 14 queue becomes