队列
1 #include <iostream> 2 #include <queue> 3 using namespace std; 4 struct Node 5 { 6 int num; 7 int w; 8 }node; 9 int main() 10 { 11 queue<Node> q; 12 int n; 13 cin >> n; 14 for(int i = 1; i <= n; i++) 15 { 16 node.num = i; 17 cin >> node.w; 18 q.push(node); 19 } 20 while(q.size() >= 2) 21 { 22 cout << q.front().num << " " << q.front().w << endl; 23 q.pop(); 24 node = q.front(); 25 q.pop(); 26 q.push(node); 27 } 28 cout << "size" << q.size() << endl; 29 cout << q.front().w << endl; 30 return 0; 31 }
1 #include <iostream> 2 #include <queue> 3 #include <stdio.h> 4 using namespace std; 5 6 int main() 7 { 8 queue<int> q; 9 int n; 10 cin >> n; 11 int cmp; 12 for(int i = 0; i < n; i++) 13 { 14 cin >> cmp; 15 q.push(cmp); 16 } 17 cout << "size»" << q.size() << endl; 18 cout << "队首" << q.front() << endl; 19 cout << "队尾" << q.back() << endl; 20 while(!q.empty()) 21 { 22 cout << q.front() << endl; 23 q.pop(); 24 } 25 return 0; 26 }