OVREVIEW
队列
1.AcWing829.模拟队列
#include<iostream>
using namespace std;
const int MAX = 100010;
typedef struct {
int head;
int tail;
int data[MAX];
} Queue;
Queue queue1;
void queue_push(Queue &queue, int x) {
queue.data[queue.tail] = x;
queue.tail++;
}
int queue_pop(Queue &queue) {
int ret = queue.data[queue.head];
queue.head++;
return ret;
}
int queue_head(Queue &queue) {
return queue.data[queue.head];
}
bool queue_empty(Queue &queue) {
if (queue.head < queue.tail) return false;
return true;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int m; cin >> m;
string opt;
int x;
int data;
while (m--) {
cin >> opt;
if (opt == "push") {
cin >> x;
queue_push(queue1, x);
} else if (opt == "pop") {
queue_pop(queue1);
} else if (opt == "empty") {
queue_empty(queue1) ? cout << "YES" << endl : cout << "NO" << endl;
} else {
data = queue_head(queue1);
cout << data << endl;
}
}
//for (int i = queue1.head; i < queue1.tail; ++i) cout << queue1.data[i] << " ";
return 0;
}
2.AcWing154.滑动窗口
单调队列
tips:文章内容参考acwing算法刷题课程,题解图示内容及代码根据老师课程、以及自己对知识的理解,进行二次整理和部分补充,仅供学习参考使用,不可商业化。