c语言 中缀、后缀 算术表达式求值用栈实现 #include<stdio.h> #include<string.h> #include<malloc.h> #include<stdlib.h> #define MaxSize 50 typedef struct { float data[MaxSize]; int top; }OpStack; typedef struct { char data[MaxSize]; int top; }SeqStack; ...
1.首先初始化两个工作栈,其中 OPTR 栈的栈底元素是#,即初始化后立即将#入栈到 OPTR 栈。 2.依次读入表达式中的字符,是数字字符,将其转化为对应float,当读入到算符字符时先将此float入栈OPND。 3. 若是运算符将 OPTR 栈顶的运算符与当前读入的运算符比较优先级后再执行相应的操作。其中栈顶元素优先级小于...
c 下面是用栈实现中缀表达式求值的示例代码: #include <stdio.h> #include <stdlib.h> #include <ctype.h> #define MAX_STACK_SIZE 100 typedef struct { int top; int data[MAX_STACK_SIZE]; } Stack; void init(Stack *s) { s->top = -1; }...