我自己写的代码,大家帮忙找找错误,运行结果是乱码:
#include <stdio.h>
#include <malloc.h>
#define S_SIZE 100
#define STACKINCREAMENT 10
struct SqStack{
    int *base;
    int *top;
    int stacksize;
};
void InitStack(SqStack &S){
    S.base=(int*)malloc(S_SIZE*sizeof(int));
    S.top=S.base;
    S.stacksize=S_SIZE;
}
int StackEmpty(SqStack S){
    if(S.base==S.top)return 1;
    else return 0;
}
void GetTop(SqStack &S,int &e){
    e=*(S.top--);
}
void push(SqStack &S,int e){
    if(S.top-S.base>=S.stacksize){
        S.base=(int*)realloc(S.base,(S.stacksize+STACKINCREAMENT)*sizeof(int));
        S.top=S.base+S.stacksize;
        S.stacksize+=STACKINCREAMENT;
    }
    *S.top++=e;
}
void pop(SqStack &S,int &e){
    if(S.base!=S.top) e=*--S.top;
}
void InversePolandExpression(char Buffer[],int i){
    SqStack s,t;
    InitStack(s);
    InitStack(t);
    int j=0,e,A[10],h=0,l=0;
    for(j=0;j<i;j++){
        if(Buffer[j]=='(') {
            push(s,Buffer[j]);
            push(t,Buffer[j]);
        }
        else if(Buffer[j]=='a'||Buffer[j]=='b'||Buffer[j]=='c')
                 push(s,Buffer[j]);
             else{
                if(Buffer[j]=='+'||Buffer[j]=='-'||Buffer[j]=='*'||Buffer[j]=='/')
                    push(t,Buffer[j]);
                if(e!=')') {
                    GetTop(s,e);
                    while(e!='('){
                        A[h]=e;
                        h++;
                        pop(s,e);
                        GetTop(s,e);
                    }
                    pop(s,e);
                    for(l=h-1;l>-1;l--)printf("%d",A[l]);
                    GetTop(t,e);
                    while(e!='('){
                        printf("%d",e);
                        pop(t,e);
                        GetTop(t,e);
                    }
                    pop(t,e);
                }
            }
    }
}
int main()
{
    int i=0;
    char Buffer[100];
    gets(Buffer);
    while(Buffer[i]) i++;
    InversePolandExpression(Buffer,i);
    return 0;
}