Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

Home Library Index Site Map  Links Search About

Stack

 

STL stack

#include <iostream>
#include <stack>
#include <deque>
using namespace std;

int main(void)

{
// Make a stack using a deque container

stack<int,deque<char> > s; // see notes

// Push the stack

char c ='z';
cout << "Pushing the stack..." << endl;
for(int i=0;i<26;i++) {
s.push(c);
c--;
cout << s.top();
}

// Pop the stack

cout << "\nPopping the stack..." << endl;
for(int i=0;i<26;i++) {
cout << s.top();
s.pop();
}

while(!cin.get())
;
return 0;

}
Complex incantations are necessary to summon up some STL containers. This example makes a stack from a deque container. The declarations :
stack<int,vector<int> > s;
or
stack<int,deque<int> > s;
make a stack of ints from a vector and deque respectively.
This is because the stack STL container is an adaptor, that is a container made from another container.
Home Library Index Top

 

STL Database
Arrays
Binary File Input / Output
Character Input
Containers
Standard Template Library
Streams
Templates
Utility Functions
Win32 Programming
Miscellaneous
 

 
copyright notice

Copyright Robert Mitchell. Last Revised : 22 June, 2000

e-mail me
1