Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/stack"

From cppreference.com
< cpp‎ | container
(expand description)
Line 8: Line 8:
 
}}  
 
}}  
  
The {{tt|std::stack}} class is a container adapter that gives the programmer the functionality of a stack - specifically, a LIFO (last-in, first-out) data structure.  
+
The {{tt|std::stack}} class is a container adapter that gives the programmer the functionality of a stack - specifically, a FILO (first-in, last-out) data structure.
 +
 
 +
The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The stack pushes and pops the element from the back of the underlying container, known as the top of the stack.
  
 
===Template parameters===
 
===Template parameters===
{{param list begin}}
+
 
{{param list item | T | The type of the stored elements.}}
+
The underlying container type {{tt|Container}} must implement the following functions:
{{param list item | Container | The type of the underlying container to use to store the elements. The container must satisfy the requirements of {{concept|SequenceContainer}}. Additionally, it must provide the following functions with the usual semantics:
+
  
 
* {{tt|back()}}
 
* {{tt|back()}}
Line 19: Line 20:
 
* {{tt|pop_back()}}
 
* {{tt|pop_back()}}
  
The standard containers {{c|std::vector}}, {{c|std::deque}} and {{c|std::list}} satisfy these requirements.  
+
The standard containers {{tt|std::vector}}, {{tt|std::deque}} and {{tt|std::list}} can be used.
}}{{param list end}}
+
  
 
===Member types===
 
===Member types===

Revision as of 07:08, 23 April 2013

 
 
 
 
Defined in header <stack>
template<

    class T,
    class Container = std::deque<T>

> class stack;

The std::stack class is a container adapter that gives the programmer the functionality of a stack - specifically, a FILO (first-in, last-out) data structure.

The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The stack pushes and pops the element from the back of the underlying container, known as the top of the stack.

Contents

Template parameters

The underlying container type Container must implement the following functions:

  • back()
  • push_back()
  • pop_back()

The standard containers std::vector, std::deque and std::list can be used.

Member types

Template:cpp/container/dcl list container typeTemplate:cpp/container/dcl list value typeTemplate:cpp/container/dcl list size typeTemplate:cpp/container/dcl list referenceTemplate:cpp/container/dcl list const reference
Member type Definition

Member functions

Template:cpp/container/dcl list constructorTemplate:cpp/container/dcl list destructorTemplate:cpp/container/dcl list operator=Template:cpp/container/dcl list topTemplate:cpp/container/dcl list emptyTemplate:cpp/container/dcl list sizeTemplate:cpp/container/dcl list pushTemplate:cpp/container/dcl list emplaceTemplate:cpp/container/dcl list popTemplate:cpp/container/dcl list swapTemplate:cpp/container/dcl list c
Element access
Capacity
Modifiers

Member objects

Non-member functions

Template:cpp/container/dcl list operator cmpTemplate:cpp/container/dcl list swap2

Helper classes

Template:cpp/container/dcl list uses allocator