- //
- // CopyRight(c) 2009, YOYO, All Rights Reserved.
- // Author: LIN YiQian
- // Created: 2009/08/24
- // Describe: STL queue 使用DEMO
- //
- #include <iostream>
- #include <queue>
- using namespace std;
- typedef queue<int> INT_QUE;
- void main(void)
- {
- INT_QUE intQue;
- int x;
- // Push
- cout << "Please input some Non-negative integer(put negative integer to finish input): " << endl;
- while (cin>>x)
- {
- if (x<0) break;
- intQue.push(x);
- }
- // Size
- cout << "Queue Size: " << intQue.size() << endl;
- // Empty?
- cout << "Queue Empty?: " << boolalpha << intQue.empty() << endl;
- // Change Front Element & Back Element
- {
- cout << "Queue front Element: " << intQue.front() << " Change to 99" << endl;
- intQue.front() = 99;
- cout << "Queue back Element: " << intQue.back() << " Change to 33" << endl;
- intQue.back() = 33;
- }
- // Print Queue
- {
- cout << "Queue: ";
- while (!intQue.empty())
- {
- cout << intQue.front() << " ";
- intQue.pop();
- }
- cout << endl;
- }
- system("pause");
- }