栈(stack):
#include <iostream>
#include <stack>
using namespace std;
int main()
{
stack<int> s;
if(s.empty())
cout<<"empty"<<endl; //empty
s.push(1);
s.push(6);
s.push(66);
cout<<s.size()<<endl; //3
s.pop();
cout<<s.size()<<endl; //2
cout<<s.top()<<endl; //6
cout<<s.size()<<endl; //2
system("pause");
return 0;
}
队列(queue):
#include <iostream>
#include <queue>
using namespace std;
int main()
{
queue<int> q;
if(q.empty())
cout<<"empty"<<endl; //empty
q.push(1);
q.push(6);
q.push(66);
cout<<q.front()<<endl; //1
cout<<q.size()<<endl; //3
q.pop();
cout<<q.size()<<endl; //2
q.push(10);
cout<<q.back()<<endl; //10
cout<<q.front()<<endl; //6
system("pause");
return 0;
}