表达式树求值
code: #include <iostream> using namespace std; typedef enum { NUM, ADD, SUB, MUL, DIV } Type; #define OPERATOR_CHAR(n) ("+-*/"[n->type - ADD]) typedef struct BN { union { double number; struct BN *children[2]; } u; Type type; BN() { for (int i = 0; i < 2; i++) u.children[i] = nullptr; } } Node; bool isdigit(char s) { if (s >= ‘0‘ && s <= ‘9‘) return true; return false; } void parse(Node *& n, char *& s) { if (*s == ‘\0‘ || n) return ; else { n = new BN(); if (isdigit(*s)) { n->type = NUM; n->u.number = double(*s - ‘0‘); s++; return ; } else { switch (*s) { case ‘+‘: n->type = ADD; break;