What are some good applications (examples) of Stacks and Queues; in real life?
Well obviously a stack of dinner plates behaves like a Stack, and a line of customers at a store behaves like a Queue, but I'm sure that's not what you mean. The way I usually see them is in search algorithms, like the order in which one considers potential paths the traveling salesman problem, which certainly is a real-life problem that gets solved using these data structures. I feel I'm probably not answering your question, but at least I can see what answers others give.
Those are example I have thought of already. But I can't think of many examples of useful stacks, where the stacked elements aren't identical. A time line of events is like a stack , in sci-fi movies etc. when the go back in time and reorder the stack, and various pops turn out differently in the various futures . Another similar example of a 'real' stack is: undo/redo history, on a text editor/similar
I guess a school bus (single door) is also a bit like a stack, if the kids get on at the back first , and fill, until at the school. Then empty from the front of the bus... Can you think of some more good ones?
Motor vehicles form queues at traffic lights, A train's engine and carriages could be changed like a queue, There must be some more good applications that just aren't so obvious
We can relate stacks to some real life objects and situations, as you can see in the picture of stack of books, One can add a new book to an existing stack of books only at its top and no where else. Similarly a book cannot be added in the middle of the stack so one has to remove all the books above to add a new book at desired place. on the other hand,some Real life examples of queue are: 1. Vehicles on toll-tax bridge: The vehicle that comes first to the toll tax booth leaves the booth first. The vehicle that comes last leaves last. Therefore, it follows first-in-first-out (FIFO) strategy of queue. 2. Phone answering system: The person who calls first gets a response first from the phone answering system. The person who calls last gets the response last. Therefore, it follows first-in-first-out (FIFO) strategy of queue. 3. Luggage checking machine: Luggage checking machine checks the luggage first that comes first. Therefore, it follows FIFO principle of queue.
Postal service delivery. It is like a collection of different, linked queues and stacks. So at each point it may be a different type and at times they get combined or split!
Join our real-time social learning platform and learn together with your friends!