C++ Stacks
Syntax:
All of the above operators can be used on stacks. Equality is defined by stacks having
the same elements in the same order.
Syntax:
The empty() function returns true if the current stack is empty, and false otherwise.
Syntax:
The function pop() removes the top element of the current stack.
Related topics:
top(),
Syntax:
void push( const TYPE &val );
|
The function push() adds val to the top of the current stack. For example:
stack<int> s;
for( int i=0; i < 10; i++ )
s.push(i);
Syntax:
The size() function returns the number of elements in the current stack. For example:
stack<int> s;
for( int i=0; i < 10; i++ )
s.push(i);
cout << "This stack has a size of " << s.size() << endl;
Syntax:
The function top() returns a reference to the top element of the stack. For example, the following code
displays and empties a stack.
while( !s.empty() ) {
cout << s.top() << " ";
s.pop();
}
Related topics:
pop(),