Tag: rpn

K和R反向波兰表示法

无法弄清楚如何调用函数。 输入1 2 3 + + [Enter] //注意输入之间有空格 输出6 //这是正确的 1 – >当程序编译时,语句调用函数getop(s)。 2 – >在getop()函数中,它将调用getch()函数,该函数又调用getchar(),因此在此步骤中它将读取1作为输入并返回它。 3 – >现在它检查c是否为数字,这是真的所以它将再次调用getch()读取空间,返回其值,现在它检查它是否为数字,否则被评估为false,然后它移动到下一个声明。 4 – >最后将执行ungetch(),在缓冲区中保存1 在这一步,我无法弄清楚如何读取输入以及getch和ungetch的用途 #define MAXOP 100 #define NUMBER ‘0’ int getop(char[]); void push(double); double pop(void); main() { int type; double op2; char s[MAXOP]; while((type=getop(s)) { switch(type) { //Here all operation are performed as push pop […]