You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
878 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
vector<int> v1;
void Pop() {
q.pop();
}
int Top() {
return q.front();
}
void Delete(int x) {
//找到第一个x值并删除掉
while (q.front() != x) {
v1.push_back(q.front());
q.pop();
}
//删除x
q.pop();
while (!q.empty()) {
v1.push_back(q.front());
q.pop();
}
//复制回来
for (int i = 0; i < v1.size(); i++)q.push(v1[i]);
}
const int N = 7;
int a[N] = {1, 3, 3, 5, 6, 8, 9};
int main() {
//初始化队列
for (int i = 0; i < N; i++) q.push(a[i]);
//测试Top
cout<<Top()<<endl;
//测试Pop
Pop();
//测试Delete
Delete(3);
//输出队列内容
while(!q.empty()){
cout << q.front() << " ";
q.pop();
}
return 0;
}