?

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NN 100
struct wq
{
?char x;? //值
?wq* link; //鏈接
};
//棧中元素個數(shù)
int all=0;
//入棧
void push(wq* me,char op);
//輸出棧中元素
void display(wq* me);
//查找棧中元素的級別
int find(wq * me);
//找到尾指針
wq * set(wq * me);
void main()
{
?char a[NN];? // 定義一個數(shù)組接受輸入
?cout<<"輸入表達(dá)式:"<<endl;
?gets(a);
?int? low=222,high=0;? //標(biāo)識運算符的級別
?wq * who = new wq;?? //創(chuàng)建空棧
?who->link=NULL;
?for(int o=0;o<NN && a[o]!='\0';o++)? //遍歷表到式
?{
? switch(a[o])
? {
? case '$':
?? low =9;break;
? case '*':
? case '/':
?? low = 7;break;
? case '+':
? case '-':
?? low = 5;
?? break;
? case '(':
?? low=13;
?? break;
? case ')':
?? low=333;
?? break;
? default:
?? low = 222;
?? break;
? };
? if(low==333)
? {
?display(who);
?low=find(who);
? }
? else if(low==222 || low<high || low==high)? //沒有算術(shù)運算符 && 不為"("括號
? {
??? cout<<a[o];
? }
? else
?? {
??? push(set(who),a[o]);
?if(low==13)
??high = 0;

?else
??? high = low;
?? }
?}
?display(who);
?cout<<"\t\t\t\ta"<<"\n";
?flushall();
?
? cout<<"\t\t\t\ta"<<"\n";
?flushall();
?flushall();
getchar();
}
//入棧
void push(wq* me,char op)
{
?me->link = new wq;
?me->link->x= op;
?me->link->link=NULL;
?all++;
}
//出棧
void display(wq* me)
{
?wq * here=me; //保存頭指針????
?bool real=true;
?while(real)
?{
? me=here;? //還原頭指針
? for(int p=0;p<all;p++)??
?? me = me->link;??? //防止產(chǎn)生出棧指針
? if(me->x=='('|| all==0)
? {
?? real=false;
? }
? else
? {?
?? cout<<me->x;
? }
? if(all!=0)
? free(me);
? all--;

?}
}
int find(wq * me)
{
?int num;
??? for(int i=0;i<all;i++)
??me=me->link;
?switch (me->x)
?{
? case '$':
?? num =9;break;
? case '*':
? case '/':
?? num = 7;break;
? case '+':
? case '-':
?? num = 5;
?? break;
? default:
?? num = 222;
?? break;
?};
?return num;
}
//重置尾指針
wq * set(wq * me)
{
??? for(int i=0;i<all;i++)
??me=me->link;
?me->link=NULL;
?return me;
}