逆波兰式的转换 总是输出中断 求大佬帮忙

程序思路应该是对的 也能正确输入 但是输出时总是中断 输出的部分也是对的 求大佬看看到底是什么问题
#include #include typedef struct Node{ char data; struct Node next;}Node,*pNode;typedef struct Stack{ pNode top;}Stack,*pStack;pStack createStack(){ pStack pstack; pstack=(pStack)malloc(sizeof(Stack)); pstack->top=NULL; return pstack;}void Push(pStack pstack,char c){ pNode p; p=(pNode)malloc(sizeof(Node)); p->data=c; p->next=pstack->top; pstack->top=p;}void Pop(pStack pstack){ pNode p; p=pstack->top; char item; item=pstack->top->data; printf("%c",item); pstack->top=pstack->top->next; free(p);}void deletetop(pStack pstack){ pNode p; p=pstack->top; pstack->top=pstack->top->next; free(p);}int first(char a,char b){ int a1; if(a=='+') { if(b==''||b=='/') a1=0; else if(b=='-') a1=1; } else if(a=='-') { if(b=='*'||b=='/') a1=0; else if(b=='+') a1=1; } else if(a=='*') a1=1; else if(a=='/') a1=1; return a1;}void transfo(pStack pstack){ char c; int a; while((c=getchar())!='\n') { if(c>96&&ctop->data=='+'||pstack->top->data=='-'||pstack->top->data=='*'||pstack->top->data=='/') { a=first(c,pstack->top->data); if(a==0) { while(a==0) { Pop(pstack); } Push(pstack,c); } else if(a==1) { Push(pstack,c); } } else if(pstack->top->data=='(') Push(pstack,c); else if(pstack->top==NULL) Push(pstack,c); } else if(c=='(') { Push(pstack,c); } else if(c==')') { while(pstack->top->data!='(') { Pop(pstack); } // if(pstack->top->data=='(') deletetop(pstack); } } while(pstack->top!=NULL) { Pop(pstack); }}int main(){ pStack pstack; pstack=createStack(); transfo(pstack); return 0;}

1个回答

应该有个插入代码片的功能,你这代码换行都没有,谁愿意看……

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问