CARVIEW |
Select Language
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 19 Jul 2025 14:09:10 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"7138-/Ivpyh44WQV0I4zkjic6fqc7IEg"
Content-Encoding: gzip
Stacks are a type of container adaptor, specifically designed to operate in a LIFO context (last-in first-out), where elements are inserted and extracted only from one end of the container.
stacks are implemented as container adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. Elements are pushed/popped from the "back" of the specific container, which is known as the top of the stack.
The underlying container may be any of the standard container class templates or some other specifically designed container class. The container shall support the following operations:
The standard container classes vector, deque and list fulfill these requirements. By default, if no container class is specified for a particular stack class instantiation, the standard container deque is used.
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
stack
- stack::stack
member functions
non-member overloads
non-member specializations
-
uses_allocator<stack>C++11
-
class template
<stack>
std::stack
template <class T, class Container = deque<T> > class stack;
LIFO stack
stacks are implemented as container adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. Elements are pushed/popped from the "back" of the specific container, which is known as the top of the stack.
The underlying container may be any of the standard container class templates or some other specifically designed container class. The container shall support the following operations:
- empty
- size
- back
- push_back
- pop_back
The standard container classes vector, deque and list fulfill these requirements. By default, if no container class is specified for a particular stack class instantiation, the standard container deque is used.
Template parameters
- T
- Type of the elements.
Aliased as member type stack::value_type. - Container
- Type of the internal underlying container object where the elements are stored.
Its value_type shall be T.
Aliased as member type stack::container_type.
Member types
member type | definition | notes |
---|---|---|
value_type | The first template parameter (T) | Type of the elements |
container_type | The second template parameter (Container) | Type of the underlying container |
size_type | an unsigned integral type | usually the same as size_t |
member type | definition | notes |
---|---|---|
value_type | The first template parameter (T) | Type of the elements |
container_type | The second template parameter (Container) | Type of the underlying container |
reference | container_type::reference | usually, value_type& |
const_reference | container_type::const_reference | usually, const value_type& |
size_type | an unsigned integral type | usually, the same as size_t |
Member functions
- (constructor)
- Construct stack (public member function)
- empty
- Test whether container is empty (public member function)
- size
- Return size (public member function)
- top
- Access next element (public member function)
- push
- Insert element (public member function)
- emplace
- Construct and insert element (public member function)
- pop
- Remove top element (public member function)
- swap
- Swap contents (public member function)
Non-member function overloads
- relational operators
- Relational operators for stack (function)
- swap (stack)
- Exchange contents of stacks (public member function)
Non-member class specializations
- uses_allocator<stack>
- Uses allocator for stack (class template)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us