队列和栈 数据结构 实验 程序

上传人:正** 文档编号:40962537 上传时间:2018-05-27 格式:DOC 页数:4 大小:20.50KB
返回 下载 相关 举报
队列和栈  数据结构 实验 程序_第1页
第1页 / 共4页
队列和栈  数据结构 实验 程序_第2页
第2页 / 共4页
队列和栈  数据结构 实验 程序_第3页
第3页 / 共4页
队列和栈  数据结构 实验 程序_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《队列和栈 数据结构 实验 程序》由会员分享,可在线阅读,更多相关《队列和栈 数据结构 实验 程序(4页珍藏版)》请在金锄头文库上搜索。

1、#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(Se

2、qQueue * 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 P

3、op(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 CTPost

4、Exp(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 +: cas

5、e -: 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);

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号