#include #include #include #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 #define OK 1 #define OVERFLOW -2 #define ERROR 0 #define TRUE 1 #define FALSE 0 typedef int Selemtype; typedef int Status; #define MAX 50 char string1[MAX]; //定义两个字符串分别存放中缀表达式和后缀表达式 char string2[MAX]; int result; typedef struct { Selemtype *base; //在构造之前和销毁之后,base 的值为NULL Selemtype *top; //栈顶指针 int stacksize; //当前分配的存储空间,以元素为单位 }SqStack; Status InitStack(SqStack *S); Status Push(SqStack *S,Selemtype e); Status Pop(SqStack *S,Selemtype e); Status InitStack(SqStack *S) { //构造一个空栈S S->base=(Selemtype*)malloc(STACK_INIT_SIZE*sizeof(Selemtype)); if(
S->base) return OVERFLOW; //存储分配失败 S->top=S->base; S->stacksize=STACK_INIT_SIZE; return OK; } Status Push(SqStack *S,Selemtype e) { //插入元素e 为新的栈顶元素 if(S->top-S->base>=S