#include
using namespace std;
void infixtopostfix(char infix[],char s2[],char &top2)//infix为中缀表达式,s2可以保存最终结果
{ //top2为结果栈的栈顶指针
int maxsize;
char s1[maxsize]; //s1为中转栈
int top1= -1;
int i =0;
while(infix[i]!= ‘\0’)
{
if(‘0’<=infix[i]&&infix[i]<=‘9’)//判断是否为数字
{
top2++;
s2[top2]=infix[i];
i++
}
else if(infix[i]==’(’)
{
top1++;
s1[top1]=infix[i];
i++
}
else if(infix[i]=='+'||
infix[i]=='-'||
infix[i]=='*'||
infix[i]=='/')
{
if(top1=='-1'||
s1[top1]=='('||
getPriority(infix[i])>getPriority(s1[top1])
)
{
top1++;
s1[top1]=infix[i];
i++;
}
else
{
top2++;
s2[top2]=s1[top1];
top1--;
}
}
else if(infix[i]==')')
{
while(s1[top1]!='(')
{
top2++;
s2[top2]=s1[top1];
}
top1--;//top1减一,忽略(
i++;
}
}
while(top1!='-1')
{
top2++;
s2[top2]=s1[top1];
top1--;
}
}