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

- 10-31-2009, 06:19 PMSrceeHelp with stacks
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?

- 10-31-2009, 06:35 PMr035198x
What do

**you**think? - 10-31-2009, 06:43 PMJosAH
It would be a stack on steroids.

kind regards,

Jos - 11-01-2009, 09:35 AMSrcee
It wouldn't be a mistake because we can add/remove elements from the middle of a single linked list

- 11-01-2009, 10:08 AMJosAH
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 - 11-01-2009, 11:23 AMSrcee