问题及描述:
/*
*烟台大学计控学院
*作 者:白晓娟
*完成日期:2016年10月08日
*问题描述:利用sqstack.h中栈的基本运算,实现将一个中缀表达式转换为对应的后缀表达式的算法。例如,输入(56-20)/(4+2),输出后缀表达式::56#20#-4#2#+/要求在数字后加#。
*/
代码:
main.cpp
#include"sqstack.h"
#include<stdio.h>
int main()
{
char exp[]="(56-20)/(4+2)"; //可将exp改为键盘输入
char postexp[200];
trans(exp,postexp);
printf("中缀表达式:%s\n",exp);
printf("后缀表达式:%s\n",postexp);
return 0;
}
sqstack.h:
#ifndef SQSTACK_H_INCLUDED
#define SQSTACK_H_INCLUDED
#define MaxSize 100
typedef char ElemType;
typedef struct
{
ElemType data[MaxSize];
int top; //栈指针
} SqStack; //顺序栈类型定义
st