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.
|
|
|
|
|