Posted 2021-03-19算法2 minutes read (About 277 words)利用中缀表达式实现表达式求值原理:给出中缀表达式,求出表达式的值。利用栈来模拟表达式树的操作。Read more
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; }}