资源预览内容
第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
亲,该文档总共4页全部预览完了,如果喜欢就下载吧!
资源描述
#include #define StackSize 100 #define QueueSize 100 #define DataType chartypedef struct DataType data100; int front,rear; SeqQueue;typedef struct DataType data100; int top; SeqStack;void InitQueue(SeqQueue * Q) Q-front=0; Q-rear=0; int QueueEmpty(SeqQueue * Q) return Q-rear=Q-front; void EnQueue(SeqQueue * Q, DataType x) if (Q-rear+1)%QueueSize=Q-front) printf(“Queue overflow“); else Q-dataQ-rear=x; Q-rear=(Q-rear+1)%QueueSize; void InitStack(SeqStack * S) S-top=-1; void Push(SeqStack * S,DataType x) if (S-top=StackSize-1)printf(“stack overflow“); else S-top=S-top+1; S-dataS-top=x; DataType Pop(SeqStack * S) if(S-top=-1) printf(“stack underflow“); else return S-dataS-top-; DataType GetTop(SeqStack * S) if(S-top=-1) printf(“stack empty“); else return S-dataS-top; int Priority(DataType op) switch(op) case (: case #:return(0); case -: case +:return(1); case *: case /:return(2); void CTPostExp(SeqQueue *Q) SeqStack *S,OS; char c,t; S= InitStack(S); Push(S,#); do c=getchar();switch(c) case :break;case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: EnQueue(Q,c); break; case (:Push(S,c); break; case ): case #: do t=Pop(S); if(t!=( while(t!=( break; case +: case -: case *: case /: while(Priority(c)front=(Q-front+1)%QueueSize; return Q-data(Q-front+QueueSize-1)%QueueSize; int CPostExp(SeqQueue * Q) SeqStack VS,* S; char ch;int x,y; S= InitStack(S); while(!QueueEmpty(Q) ch=DeQueue(Q); if(ch=0tail=Q-rear; while(!QueueEmpty(Q) printf(“%2c“,DeQueue(Q); Q-front=head;Q-rear=tail; printf(“%d“,CPostExp(Q);
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号