#include <iostream> #include <deque>//front push pop back push pop [] at() #include <queue> #include <stack> #include <list> //remove using namespace std; void listTest() { int iArray[]={1,2,3,4,5,3,3,3,3,3,6}; list<int> listInt(iArray,iArray+11); list<int>::iterator it_list=listInt.begin(); for (;it_list!=listInt.end();++it_list) { cout<<*it_list<<" "; } cout<<endl; cout<<"=============================="<<endl; int i; for(i=0;i<11;i++)// (i-=1;i>=0;--i) { listInt.push_front(iArray[i]); } /////////////////////////////////////// for(i=0;i<11;i++)// { listInt.pop_front(); } //----------------------------------- cout<<"pop front:"<<endl; it_list=listInt.begin(); for (;it_list!=listInt.end();++it_list) { cout<<*it_list<<" "; } cout<<endl; cout<<"=============================="<<endl; //////////////////////////////////////////////// for(i-=1;i>=0;--i) { listInt.push_front(iArray[i]); } cout<<"push front:"<<endl; it_list=listInt.begin(); for (;it_list!=listInt.end();++it_list) { cout<<*it_list<<" "; } cout<<endl; cout<<"=============================="<<endl; for(i=0;i<11;i++)// { listInt.pop_back(); } cout<<"pop back:"<<endl; it_list=listInt.begin(); for (;it_list!=listInt.end();++it_list) { cout<<*it_list<<" "; } cout<<endl; cout<<"=============================="<<endl; listInt.remove(3); cout<<"remove 3:"<<endl; it_list=listInt.begin(); for (;it_list!=listInt.end();++it_list) { cout<<*it_list<<" "; } cout<<endl; /* 1 2 3 4 5 3 3 3 3 3 6 ============================== pop front: 1 2 3 4 5 3 3 3 3 3 6 ============================== push front: 1 2 3 4 5 3 3 3 3 3 6 1 2 3 4 5 3 3 3 3 3 6 ============================== pop back: 1 2 3 4 5 3 3 3 3 3 6 ============================== remove 3: 1 2 4 5 6 Press any key to continue */ } void stackTest() { int iArray[]={1,2,3,4,5,3,3,3,3,3,6}; //stack<int> stackInt(iArray,iArray+11); stack<int> stackInt; for (int i=0;i<sizeof(iArray)/sizeof(int);i++) { stackInt.push(iArray[i]); } cout<<"pop~:"<<endl; int len=stackInt.size(); for (i=0;i<len;i++) { cout<<stackInt.top()<<" "; stackInt.pop(); } cout<<endl; /* pop~: 6 3 3 3 3 3 5 4 3 2 1 Press any key to continue */ } void queueTest() { int iArray[]={1,2,3,4,5,3,3,3,3,3,6}; //queue<int> queueInt(iArray,iArray+11); queue<int> queueInt; for (int i=0;i<11;i++) { queueInt.push(iArray[i]); } //queue<int>::iterator it_queue=queueInt.begin(); //cout<<queueInt.end()<<endl; //////////////////////////////// cout<<"pop~:"<<endl; int len=queueInt.size(); for (i=0;i<len;i++) { cout<<queueInt.front()<<" "; queueInt.pop(); } cout<<endl; /* pop~: 1 2 3 4 5 3 3 3 3 3 6 Press any key to continue */ } void main() { listTest();return; //stackTest();return; //queueTest();return; int iArray[]={1,2,3,4,5,3,3,3,3,3,6}; //deque<int> deInt(iArray,iArray+11); deque<int> deInt; for (int i=0;i<11;i++) { deInt.push_back(iArray[i]); } deque<int>::iterator itorDeque=deInt.begin(); for (;itorDeque!=deInt.end();++itorDeque) { cout<<*itorDeque<<" "; } cout<<endl; cout<<"=============================="<<endl; for(i=0;i<11;i++)// (i-=1;i>=0;--i) { deInt.push_front(iArray[i]); } for(i=0;i<11;i++)// { deInt.pop_front(); } itorDeque=deInt.begin(); for (;itorDeque!=deInt.end();++itorDeque) { cout<<*itorDeque<<" "; } cout<<endl; for(i-=1;i>=0;--i) { deInt.push_front(iArray[i]); } cout<<"push front:"<<endl; itorDeque=deInt.begin(); for (;itorDeque!=deInt.end();++itorDeque) { cout<<*itorDeque<<" "; } cout<<endl; for(i=0;i<11;i++)// { deInt.pop_back(); } cout<<"pop back:"<<endl; itorDeque=deInt.begin(); for (;itorDeque!=deInt.end();++itorDeque) { cout<<*itorDeque<<" "; } cout<<endl; deInt.push_front(0); cout<<"at:"<<endl; for (i=0;i<deInt.size();i++) { cout<<deInt.at(i)<<" "; } cout<<endl; /* 1 2 3 4 5 3 3 3 3 3 6 ============================== 1 2 3 4 5 3 3 3 3 3 6 push front: 1 2 3 4 5 3 3 3 3 3 6 1 2 3 4 5 3 3 3 3 3 6 pop back: 1 2 3 4 5 3 3 3 3 3 6 at: 0 1 2 3 4 5 3 3 3 3 3 6 Press any key to continue */ }