voidmain() { queue<int> q; int num; cout<<"------Test for Queue-------"<<endl; cout<<"Input number:"<<endl; while(cin>>num)//输入数字 { q.push(num); } cout<<"Now the Queue has "<<q.size()<<" numbers."<<endl; cout<<"The first is "<<q.front()<<endl; cout<<"The last is "<<q.back()<<endl; cout<<"All numbers:"<<endl; while(!q.empty()) { cout<<q.front()<<" "; q.pop(); } cout<<"Now the Queue has "<<q.size()<<" numbers."<<endl; system("Pause"); }
IO:
1 2 3 4 5 6 7
输入:1234567 q 输出: Now the Queue has 7 numbers. The first is1 The last is7 All numbers: 1234567 Now the Queue has 0 numbers.