Posted 2021-03-17算法a few seconds read (About 71 words)栈的数组模拟 12345678910111213141516171819202122232425262728293031323334#include <iostream>using namespace std;const int N = 100010;int stack[N], top, m;string mode;void init() { top = 0;}void push(int x) { stack[++top] = x;}void pop() { top--;}int size() { return top;}int main() { cin >> m; init(); while(m--) { int x; cin >> mode; if(mode == "push") cin >> x, push(x); if(mode == "pop") pop(); if(mode == "empty") cout << (size() == 0 ? "YES\n" : "NO\n"); if(mode == "query") cout << stack[top] << endl; }} 栈的数组模拟http://blog.inverseda.top/2021/03/17/算法笔记/栈的数组模拟/AuthorInverseDaPosted on2021-03-17Updated on2023-03-30Licensed under#栈