Both act like a stack. Both have push and pop operations.
Is the difference in some memory layouts?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
std::vectorhas several accessibility and modification operations compared tostd::stack. In case ofstd::stack, you may have to perform operations only in systematic way, where you canpush()above the last element orpop()the last element.std::vectoris more flexible in that sense, where it has several operations, where you caninsert()in between orerase()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 bestd::vectororstd::listtoo.On other hand,
std::vectoris guaranteed to be a contiguous array which can be accessed usingoperator [].