Stack is a Last-in-first-out structure. Let's implement it with single linked list. Would it be a mistake if we add methods for removing/adding element in the middle/beggining of the list?
Printable View
Stack is a Last-in-first-out structure. Let's implement it with single linked list. Would it be a mistake if we add methods for removing/adding element in the middle/beggining of the list?
What do you think?
It would be a stack on steroids.
kind regards,
Jos
It wouldn't be a mistake because we can add/remove elements from the middle of a single linked list
A stack doesn't need to be implemented by a single linked list. Purists may say that you can push and pop elements to/from a stack and that's it. A more practical approach might say that more operations on stacks should be possible. The Stack implementation in Java is quite weak because behind its back you can cast a Stack to its parent class, a Vector; you can do much more with a Vector than you can do with a Stack.
kind regards,
Jos