The STL Algorithms

stack

The stack class supports a stack. Its template specification is shown here:

template <class T, class Container = deque<T> > class stack

Here, T is the type of data being stored and Container is the type of container used to hold the queue. It has the following constructor:

explicit stack(const Container &cnt = Container( ));

The stack( ) constructor creates an empty stack. By default, it uses a deque as a container, but a stack can be accessed only in a last-in, first-out manner. You may also use a vector or list as a container for a stack. The container is held in a protected member called c of type Container.

The following comparison operators are defined for stack:

==, <, <=, !=, >, >=

stack contains the following member functions:

Member

Description

bool empty( ) const;

Returns true if the invoking stack is empty and false otherwise.

void pop( );

Removes the top of the stack, which is technically the last element in the container.

void push(const value_type &val);

Pushes an element onto the end of the stack. The last element in the container represents the top of the stack.

size_type size( ) const;

Returns the number of elements currently in the stack.

value_type &top( );
cont value_type &top( ) const;

Returns a reference to the top of the stack, which is the last element in the container. The element is not removed.




C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net