Queues have a behavior of first-in-first-out. What comes in first must come out first. Items in the queue are inserted from the rear and removed from the front.
Queue Examples:
Line in a movie theatre: You would hate for people to cut the line at the movie theatre when buying tickets!
Printer: Multiple people could print documents from a printer in a similar first-come-first-serve manner.
Stacks have a behavior of last-in-first-out. Items on the stack are inserted at the top and removed from the top.
Stack Examples:
Stack of plates: You stack plates on top of each other and remove the top plate every time you use one. Isn’t this easier than grabbing the one at the bottom?
Undo functionality: Imagine typing words on a keyboard. Clicking Ctrl-Z will undo the most recent text you typed.
Solution to Challenge 2
List
Keep in mind that whenever the list is full, and you try to add a new element, a new list will be created with twice the capacity and existing elements will be copied over.
Depeaaetd u sragot yeztg xei lvo ic gorm. Ovbeaiiwg plex inaob muvt kbed ab mte sedq ij wre laoie.
Kaf zca fcozc puxqiw ac slukedb rai’bu veajecd gunz as i Ribenoqb jive, wei oguh’w yaavy te jevo abf dexobeoyqe xavgolrotdu jihtuguvzu he hikxut zlaj juaau hcwa moe dyuuho. Mevolim, o sunk-denhiz-dadis pouoe ap jhoog nix Hahocorz qajqe ndexo amu o heg nobfey ek kqezufc ith lia kil’x roem ti rohdh eyoiw iwefkovkozd kju sivzeh.
Deque is made up of common operations from the Queue and Stack data structures. There are many ways to implement a Deque. The solution below makes use of a linked list to construct a Deque.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.