#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
struct wq
{
?char name;
?struct wq * link;
};
int all = 0; // the number of all
// jin zhan
void push( wq* me ,char x );
// get the last *
wq* set( wq* me );
// get the last char
char setc(wq* me);
// display all number
void dis( wq* me );
//chose display
void chose( wq* me, char x );
// to pan duan you xian ji
int num( wq* me );
int numg( char gg );
void main()
{
?char str[30];
?wq * me = new wq;
?me->link = NULL;
?cout<<"輸入表達式:\n"<<endl;
?gets( str );
?for(int i = 0; i < 30 && str[i] != '\0'; i++)
?{
? chose( me, str[i]);
?}
?dis(me);
?cout<<endl;
?getchar();
}
// jin zhan
void push( wq* me ,char x )
{
?me = new wq;
?me -> name = x;
?me -> link = NULL;
?all++;
}
// get the last *
wq* set( wq* me )
{if( all != 0)
{
?for (int i = 1; i < all ; i++)
?{
? me = me -> link;
}
}
?return me;
}
// get the last char
char setc(wq* me)
{
?if( all != 0)
?{
??for(int i= 1; i<all;i++)
???me = me ->link;
?}
?return me->name;
}
// display all number
void dis( wq* me )
{
?wq* you;
?do{
? you = set(me);
? cout<< you -> name;
? free( you );
? all-- ;}while(all);
}
//chose display
void chose( wq* me, char x )
{
?wq* you = me;
?int how = num( me );
?int to = numg( x );
?if( to ){
?if(to < how && x != ')')? // < or ==
?{
? while( to < num(you) )
? {
?? you = set( me );
?? cout<<you->name;
?? if(all != 0 )
?? {
??? free(you);
??all--;
?? }
? }
?}
? else if( x == ')')
?{
? while( num( me ) != 44)
? {
?? you = set( me );
?? cout<<you->name;
?? if( all != 0)
?? {
??? free(you);
??? all--;
?? }
? }
?}
? else if( to > how )
? push( me , x);
else
?cout<<x;
?}
?else cout<<x;
}
// to pan duan you xian ji
int num( wq* me )
{
?switch ( setc(me) )
?{
?case '$':
? return 33;
? break;
?case '*':
?case '/':
? return 22;
? break;
?case '+':
?case '-':
? return 11;
? break;
?case '(':
? return 44;
? break;
?default: return 0;
?}
}
int numg(char gg)
{
? switch ( gg )
?{
?case '$':
? return 33;
? break;
?case '*':
?case '/':
? return 22;
? break;
?case '+':
?case '-':
? return 11;
? break;
?case '(':
? return 44;
? break;
?default: return 0;
?};
}?
?