Stack is a data structure designed to operate in LIFO (Last in First out) context. In stack elements are inserted as well as get removed from only one end.
Stack class is container adapter. Container is an objects that hold data of same type. Stack can be created from different sequence containers. If container is not provided it uses default deque container. Container adapters do not support iterators therefore we cannot use them for data manipulation. However they support push() and pop() member functions for data insertion and removal respectively.
DefinitionBelow is definition of std::stack from <stack> header file
template <class T, class Container = deque<T> > class stack;Parameters
T − Type of the element contained.
T may be substituted by any other data type including user-defined type.
Container − Type of the underlying container object.
Following member types can be used as parameters or return type by member functions.
Sr.No. Member types Definition 1 value_type T (First parameter of the template) 2 container_type Second parameter of the template 3 size_type size_t 4 reference value_type& 5 const_reference const value_type& Functions from <stack>Below is list of all methods from <stack> header.
Constructors Sr.No. Method & Description 1 stack::stack default constructorConstructs an empty stack object, with zero elements.
2 stack::stack copy constructorConstructs a stack with copy of each elements present in another stack.
3 stack::stack move constructorConstructs a stack with the contents of other using move semantics.
Destructor Sr.No. Method & Description 1 stack::~stackDestroys stack by deallocating container memory.
Member functions Sr.No. Method & Description 1 stack::emplaceConstructs and inserts new element at the top of stack.
2 stack::emptyTests whether stack is empty or not.
3 stack::operator= copy versionAssigns new contents to the stack by replacing old ones.
4 stack::operator= move versionAssigns new contents to the stack by replacing old ones.
5 stack::popRemoves top element from the stack.
6 stack::push copy versionInserts new element at the top of the stack.
7 stack::push move versionInserts new element at the top of the stack.
8 stack::sizeReturns the total number of elements present in the stack.
9 stack::swapExchanges the contents of stack with contents of another stack.
10 stack::topReturns a reference to the topmost element of the stack.
Non-member overloaded functions Sr.No. Method & Description 1 operator==Tests whether two stacks are equal or not.
2 operator!=Tests whether two stacks are equal or not.
3 operator<Tests whether first stack is less than other or not.
4 operator<=Tests whether first stack is less than or equal to other or not.
5 operator>Tests whether first stack is greater than other or not.
6 operator>=Tests whether first stack is greater than or equal to other or not.
7 swapExchanges the contents of two stack.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4