This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
#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;
}