双端循环队列操作_第1页
双端循环队列操作_第2页
双端循环队列操作_第3页
双端循环队列操作_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、题目 :在顺序存储结构上实现输出受限的双端循环队列的入列和出列 (只允许对头出列) 算 法,设每个元素表 示一个待处理的作业, 元素值表示作业的预计时间, 入队列采取 简化的作业优先原则, 若一个新提交的 作业的预计时间小于队头和队尾作业的平均 时间,则插入在队头,否则插入在队尾。(一) 需求分析1. 队列中数据为整形,输入值均为整形。2. 终端输出结果是:输入数据在队列中的插入结果。3. 程序能够实现:对输入数据进行比较,并将其插入适当位置。4. 测试数据: Enter your time : quit 023There are your works in the sequeue: 23En

2、ter your time: quit 012There are your works in the sequeue: 12 23Enter your time : quit 013There are your works in the sequeue: 13 12 23(二) 概要设计1. 抽象数据类型为ADT Queue数据对象:D=ai |ai ElemSet,i=1,2, , n,n 0 数据关系:R1=|ai-1,ai D, i=2, ,n约定其中 a1 端为队头, an 端为队尾。2. 算法Status EnDQueue(sequeue &sq1,int x)/ 输出受限的双端队列

3、的入队操作sequeue *sq1;sq1-front=N-1;sq1-rear=N-1;if(x!=0)/根据 x 的值决定插入在队头还是队尾if(sq1-front=(sq1-rear+1%N)printf(queue is full);return(NULL);elseif(xdatasq1-rear+sq1-data(sq1-front+1)%N)/2) /插入在队头 sq1-datasq1-front=x;sq1-front=sq1-front-1;elsesq1-rear=(sq1-rear+1)%N;/插入在队尾sq1-datasq1-rear=x;(三) 详细设计#includ

4、e#include#define N 30int x=1;typedef structint dataN;int front;int rear;sequeue;setnull(sq1)sequeue *sq1;sq1-front=N-1;sq1-rear=N-1;int inseq(sq1)sequeue *sq1;printf(Enter your time:quit 0n);scanf(%d,&x);if(x!=0)if(sq1-front=(sq1-rear+1%N)printf(queue is full);return(NULL);elseif(xdatasq1-rear+sq1-d

5、ata(sq1-front+1)%N)/2) sq1-datasq1-front=x;sq1-front=sq1-front-1;elsesq1-rear=(sq1-rear+1)%N; sq1-datasq1-rear=x;return(1);print(sq1)sequeue *sq1;int i;printf(There are your works in the sequeue:); for(i=sq1-front+1;idatai!=0) printf(%4d,sq1-datai);for(i=0;ifront;i+)if(sq1-datai!=0)printf(%4d,sq1-da

6、tai);main()int i;sequeue *sq;sq=(sequeue *)malloc(sizeof(sequeue);for(i=0;idatai=0;printf(n);setnull(sq);while(x!=0)inseq(sq);print(sq);printf(n);四) 调试分析由于在主函数中没有为 sq 申请结点空间,在运行时后面出现一些乱七八糟的数字, 改正后得以正常运行。五) 用户手册1. 本程序的运行环境为 DOS 操作系统,在 TC 中调用文件 B14-2.C 。2. 进入程序后按 Ctrl+F9 运行程序, 即显示提示信息: Enter your time

7、:quit 0.等待用户输入数据,每输入一个数据按下回车键,此时会显示There are your works in the sequeue :输入数据插入适当位置后的顺序Enter your time: quit 03. 直到用户输入 0,本程序结束。4. 本程序只适用于整形数据, 当输入其他类型数据时会进入死循环, 按 Ctrl+Break 键, 退出死循环。六) 测试结果Enter your time :quit 023There are your works inthe sequeue :23Enter your time:quit 012There are your works inthe sequeue :1223Enter your time :quit 013There are your works inthe sequeue :1312 23Enter your time :quit 024There are your works inthe sequeue :1312 23 24Enter your time :quit 016There are your works in the sequeue :1613122324Enter your time :quit 036There are your works in t

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论