- Double ended queue is an another type of queue an it is called as dqueue.
- A dqueue is a special type of data structure,is a homogeneous list of elements in which insertion and deletion operations are performed from both the ends.i.e) at the front and rear end of the queue.
- DQUEUE Operations,
- Insert an element from front end.
- Insert an element from rear end.
- Delete an element from front end.
- Delete an element from rear end.
- An insertion of element at front end of the queue can be done under two situations one situation is if the queue is totally empty i.e)front=0 &rear=-1 then we can insert only one element at the front end by incrementing rear pointer .
- In another situation is that, if queue is partially empty i.e)front pointer not equal to zero then we can insert the elements until front becomes zero by decrementing by 1 .
- Except these two situation it is not possible to insert an element at the front end.
- For example consider the queue is shown,in fig.Here an item 10 is already present in the first position in the queue and front pointer points to zero but rear pointer points to other than -1.
- So it is not possible to insert any element in the front end of the queue.
Delete an element from the rear end:
- To delete an element from rear end we need to check the queue is not empty then we can access the first rear element & remove the element from the queue then decrement the rear end pointer rear by 1.
- By performing repeated operation at one instance queue may become empty. if the queue is empty,then reset the front pointer front to zero and rear pointer rear to 1 as it has been done in ordinary queue.
Delete an element from front end.
Both operations are same as simple queue.so
refer this,
*******
No comments:
Post a Comment