Why can't you remove an item from the bottom of a stack data structure?


#1

Question

Why can’t you remove an item from the bottom of a stack data structure? There doesn’t seem to be a technical reason that an item can’t be removed from the bottom.

Answer

The various data structures that are used in programming languages have expected behaviors based on what those structures are. While it is certainly possible to implement a function or method to remove an element from the bottom of a stack, the data structure would no longer behave in the way that a stack is expected to behave which is Last-In-First-Out. Programmers must be able to depend on the expected behaviors and results from a data structure. Changing that can lead to unexpected results. Rather than considering adding or changing the behavior of a data structure, it is generally better to think about using some other type of data structure which has the needed behavior.