I don’t understand. I know it has to do with stacks not being vectors. Can someone explain this.
I would guess its not substitutable because stacks aren’t vectors. So if you have a situation that use vectors you won’t be able to use a stack. The second part is a guess but since if you were to create a private class then you wouldn’t know how the class is being used and might try to implement it as a vector.
This is only true if you insist that
Stackmodels a stack and nothing else. As it stands,Stackallows stack-y operations and, in addition, vector-y random-access operations. It may be a stack on steroids, but it’s still a stack.Compare that with a class named
LinkedListthat also supports methods needed for a LIFO stack. Does that make it a non-list?As an aside, note that
StackandVectorhave been out of use since year 1998.