Explain double ended queue as an array ? and what are the real world example of double ended queue. Explain?
/*If you any query do comment in the comment section else like the solution*/
An array can be used a deque by using two pointers front and rear both of them pointing to -1 initially when queue is empty, when new element is inserted rear is incremented, front is also incremented in case front and rear both are pointing to index -1. When index of rear becomes equal to size of array we say that array is full. When an element is removed, front index is incremented and if front becomes greater than the rear index then we say that queue is empty.
Browsing history uses deque in which new urls are inserted at the front of the queue which makes recent urls visited to appear at the top of the list and old urls visited is removed from the rear end after a particular point of time.
Get Answers For Free
Most questions answered within 1 hours.