Is there a difference in complexity between std :: vector used as a stack and std :: stack?

As the title asks, is there a difference in time or space between std :: vector used as the stack and std :: stack?

+4
source share
2 answers

A std::stackwraps another container. If the backup container of your stack is equal std::vector, then no, there is no difference.

The default support container, however, std::dequewhich may have different storage and time settings

See std :: stack for more details.

+4
source

No, there is no difference in complexity. std::vector- The container. std::stackis a container adapter.

std::stack std::deque , "". , , .


std::vector:

template<typename T>
using MyVectorStack = std::stack<T, std::vector<T>>;


std::stack std::deque vs std::vector - .

std::vector , . std::deque, , "pop" deque.

. std:: stack std:: deque ?

+3

Source: https://habr.com/ru/post/1675900/


All Articles