#include <iostream>
#include <stack>
#include <vector>
#include <queue>
#include <list>
#include <map>
using namespace std;
int main()
{
std::stack<int> stk;
std::vector<int> vct;
std::queue<int> qq;
std::list<int> lst;
std::map<int, std::string> mp;
for (int i = 0; i < 10; ++i)
{
stk.push(i);
}
for (int i = 0; i < 10; ++i)
{
vct.push_back(i);
}
int i = 0;
// stack traverse;
cout << endl << "stk traverse" << endl;
//iterator<int> it = vct.begin();
while (stk.size())
{
cout << stk.top();
stk.pop();
}
//vct traverse
cout << endl << "vct traverse" << endl;
while (vct.size())
{
cout << vct.back();
vct.pop_back();
//vct pop_back()// stack; first in last out;
}
cout << endl;//front
cout << "vct traverse2"<<endl;
for (int i = 0; i < 10; ++i)
{
vct.push_back(i);
}
for (int i = 0; i < vct.size(); ++i)
{
cout << vct[i];
}
cout << "vct traverse3" << endl;
for (vector<int>::iterator it = vct.begin();it!=vct.end(); ++it)
{
cout << (*it) << endl;
}
cout << endl;
cout << endl << "queue traverse" << endl;
for (int i = 0; i < 10; ++i)
{
qq.push(i);
}
while (qq.size())
{
cout << qq.front();
qq.pop();
}
cout << endl;
//========================
for (int i = 0; i < 10; ++i)
{
lst.push_back(i);
}
cout << endl << " list traverse" << endl;
// list can access the front and the last ;
// pop the front and the last;
// main is the double direction linked list;
cout << endl << " list from front to end;" << endl;
while (lst.size())
{
//cout << lst.back() << endl;
//lst.pop_back();
cout << lst.front();
lst.pop_front();
//cout << lst[2];
}
cout << endl << " list from back to front;reverse out put;" << endl;
for (int i = 0; i < 10; ++i)
{
lst.push_back(i);
}
while (lst.size())
{
cout << lst.back() << endl;
lst.pop_back();
}
}
all kinds of containers
最新推荐文章于 2024-07-15 17:53:06 发布