Problem Detail: From low OS-level function calls, to memory allocated to an application, all will primarily take a stack to perform LIFO operations. Why don’t we use queues and FIFO operations? It’s just a matter of moving pointers anyway.
Asked By : Spandan
Answered By : David Richerby
Because some things need to be done LIFO and some things FIFO. For example, when a function call returns, it needs to return to the last item on the call stack, i.e., the function that called it. It would make no sense to return to the first item on the call-stack. Conversely, if you’re serving requests, the next request you serve is the first one to enter the service queue. (It turns out that, actually, serving queues from the back can be more efficient but that has the obvious disadvantage that it risks starvation for things at the front of the queue and, in real-life queues of people, it just gives people a huge incentive to leave the queue and re-join.)
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/47347