参考算法笔记,数据结构部分栈的内容
计算中缀表达式,先转换成后缀表达式,再计算
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
using namespace std;
typedef long long LL;
struct Node{
double num; //操作数
char op; //操作符
bool flag; //flag==true代表操作数 false代表操作符
Node(double num=0,char op='\0',bool flag=false):num(num),op(op),flag(flag){
}
};
string str;
//数字放在queue中,利用stack调整运算符的位置,最终后缀表达式放在q中
stack<Node> s;
queue<Node> q;
map<char,int> op;
void transform(){
double num;
for(int i=0;i<str.size();){
if(isdigit(str[i])){
num=0;