试编写程序,a.将中缀表达式计算转换成后缀表达式。

来源:百度知道 编辑:UC知道 时间:2024/05/05 21:21:05
用c语言编写,各位大虾,谢谢啦!!!急需!!!

#include<stdio.h>
#define MaxSize 99
void trans(char str[],char exp[]) /*将算术表达式转换成后追表达式*/
{
struct
{
char data[MaxSize];
int top; /*top为栈顶*/
}op; /*定义一个含data和top的结构体*/
char ch;
int i=0,t=0;
op.top=-1;
ch=str[i]; /*将str的每一个数转换成ch*/
i++;
while(ch!='\0') /*ch对应不同的符号的时候对应的转换情况*/
{
switch(ch)
{
case'(': /*当是(的时候,将此括号存入栈tp*/
op.top++;op.data[op.top]=ch;
break;
case')':
while(op.data[op.top]!='(')
{
exp[t]=op.data[op.top];