I do understand how Stack()
and Stack
works, but I really can\'t see any scenarios where an array, List
or IEnumer
Stack and Queue use internally an array. If you were using arrays in smart ways the chances are good that you have used them in a stack or queue like fashion already. Usually you need to decide between Stack and Queue. A typical example where a Stack is needed is depth first search. If you change the collection to a queue you have implemented a breadth first search.
Another example is heavy multithreading where you pass data between a producer and consumer via a stack if the processing order is not relevant. The rationale behind this is that if much data is going to be processed it is better for the CPU to use the latest added data chunk for further processing on the other thread to get better cache locality.
And the list goes on ....