Alex Rivera | Logout

What is the major difference between a vector and a stack?

Asked 2012-01-09T08:55:57.023
33

Both act like a stack. Both have push and pop operations.

Is the difference in some memory layouts?

Edit
Report

1 Answer

2

Stack is basically a special case of vector. Theoretically speaking vector can grow as you wish. You can remove elements at any index in a vector. However, in case of a stack you can remove elements and insert them only at its top (hence a special case of vector).

In face in many libraries that provide an implementation of a stack, they generally inherit from the vector class/structures. I am not sure, but I think STL (C++) does it.

answered 2012-01-09T09:02:20.543

Your Answer