# 模拟栈

#include <iostream>

using namespace std;

const int N = 1e5 + 10;

int stk[N], tt;
int x;

void push(int x){
    stk[++tt] = x;
}

void pop(){
    tt--;
}

void query(){
    cout << stk[tt] << endl;
}

void empty(){
    if(tt > 0) cout << "NO" << endl;
    else cout << "YES" << endl;
}

int main(){
    string op;
    int m;
    cin >> m;
    while(m--){
        string s;
        cin >> op;
        if(op == "push"){
            int a;
            cin >> a;
            push(a);
        }
        else if(op == "query"){
            query();
        }
        else if(op == "pop"){
            pop();
        }
        else{
            empty();
        }
    }
    return 0;
}
#include <iostream>

using namespace std;

const int N = 1e6 + 10;

int stk[N], tt;

//插入
stk[++tt] = x;

//弹出
tt--;

//判断栈是否为空
if(tt > 0) not empty
else empty

//栈顶
stk[tt];

//*******************队列

//在队尾插入元素,在队头弹出元素
int q[N], hh, tt = -1;

//插入
q[++tt] = x;

//弹出
hh++;

//判断队列是否为空
if(hh <= tt) not empty
else empty

//取出队头元素
q[hh]
//取出队尾元素
q[tt]

# 栈与队列

1. 栈
先进后出 2. 队列
先进先出