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

std::vector has several accessibility and modification operations compared to std::stack. In case of std::stack, you may have to perform operations only in systematic way, where you can push() above the last element or pop() the last element.

std::vector is more flexible in that sense, where it has several operations, where you can insert() in between or erase() in between.

The major point is that, std::stack needs to be provided the underlying container. By default it’s std::deque, but it can be std::vector or std::list too.
On other hand, std::vector is guaranteed to be a contiguous array which can be accessed using operator [].

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)