我这个中缀表达式转后缀表达式有问题,求修改,编程小白
#include<stdio.h>#include<iostream.h>
#define TRUE 1
#define FALSE 0
#define max 50
typedef struct
{
char data[max];
int top;
}SeqStack;
void chushihua(SeqStack *S)
{
S->top=-1;
}
void compvalue(SeqStack *S,char exp[],char e[])
{
int i=0,j=0,k=0;
while(exp[i++]!='\n')
{
if(exp[i]>='0'&&exp[i]<='9'){
j++;
e[j]=exp[i];
}
if(exp[i]=='('){
S->top++;
S->data[S->top]=exp[i];
}
if(exp[i]==')')
{
while(S->data[S->top]!='('){
j++;
e[j]=S->data[S->top];
S->top--;
}
S->top--;
}
if(exp[i]=='+'||exp[i]=='-')
{
if(S->data[S->top]=='+'||S->data[S->top]=='-'||S->data[S->top]=='*'||S->data[S->top]=='/')
{
j++;
e[j]=S->data[S->top];S->top--;
S->top++;S->data[S->top]=exp[i];
}
else{
S->top++;
S->data[S->top]=exp[i];
}
}
if(exp[i]=='*'||exp[i]=='/')
{
if(S->data[S->top]=='*'||S->data[S->top]=='/')
{
j++;
e[j]=S->data[S->top];S->top--;
S->top++;S->data[S->top]=exp[i];
}
else
{
S->top++;
S->data[S->top]=exp[i];
}
}
}
while(S->top!=-1)
{
e[j++]=S->data[S->top];
S->top--;
}
while(e[k]!='\n')
{
cout<<e[k];
k++;
}
}
int main()
{
SeqStack S;
chushihua(&S);
int i=0;
char exp[20],e[20];
cout<<"请输入中缀表达式:"<<endl;
gets(exp);
chushihua(&S);
compvalue(&S,exp,e);
return 0;
}