下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include#include#define MAX 5进程数量#define RR 1时间片大小/*时间片轮转算法*/struct proint num;int arriveTime;int burst;int rt;记录进程被运行的次数struct pro *next;int TOTALTIME; 记录所有进程的总时间/函数声明struct pro* creatList();void insert(struct pro *head,struct pro *s);struct pro* searchByAT(struct pro *head,int AT);void del(struct
2、pro* p);int getCount(struct pro *head,int time);struct pro* searchEnd(struct pro *head);void move(struct pro *headF,struct pro *headT,int n);struct pro* creatList()创建链表,按照进程的到达时间排歹U,记录所有进程的信息struct pro* head=(struct pro*)malloc(sizeof(struct pro);head-next=NULL;struct pro* s;int i;TOTALTIME=0;for(i=
3、0;inum);printf(请输入到达时间:n);scanf(%d,&(s-arriveTime);printf(-请输入运行时间:n);scanf(%d,&(s-burst);TOTALTIME+=s-burst; 计算总时间s-rt=1;/rt的初始值为1s-next=NULL;insert(head,s);return head;到达队列中的进程按照其到达时间的先后顺序排列void insert(struct pro *head,struct pro *s)插入节点struct pro *p=searchByAT(head,s-arriveTime);s-next=p-next;p-n
4、ext=s;return;struct pro* searchByAT(struct pro *head,int AT) 查找第一个到达时间大于等于 AT 的节点,返回其前一个指针struct pro *p,*q;p=head;q=head-next;while(q!=NULL&q-arriveTimenext;return p;void del(struct pro* p)删除 p 的下一个节点struct pro *tmp;tmp=p-next;p-next=tmp-next;free(tmp);return;int getCount(struct pro *head,int time)察
5、看在time之前到达但未移动到运行队列的进程数量int count=0;struct pro *s,*t;s=head;t=s-next;while(t!=NULL&t-arriveTimenext;count+;/count记录当前时刻到达的进程数return count;struct pro* searchEnd(struct pro *head)查找并返回循坏队列的尾节点的前一个节点struct pro *p,*q;p=head;q=head-next;while(q-next!=head)p=q;q=q-next;return p;void move(struct pro *headF
6、,struct pro *headT,int n) 将 headF 后的 n 个节点移动到循环队列headT中struct pro *r,*s,*t;s=headF;t=s-next;r=t;/r记录要移动的第一个节点while(n1)t=t-next;n-;s-next=t-next;以上完成从原队列中摘除相关节点r,t分别为第一个和最后一个节点s=searchEnd(headT);t-next=s-next;s-next=r;void run(struct pro *head)int time=0;记录当前时间int newarrive;/新 到达进程数struct pro *runhea
7、d=(struct pro*)malloc(sizeof(struct pro);runhead-next=runhead;创建新的循环链表,存放当前就绪队列中的进程struct pro *p,*q;p=runhead;q=p-next;/q记录当前应当运行的进程while(time0)move(head,runhead,newarrive);/将 head 后的 newarrive 个节点移动至U runhead 队列I中if(runhead-next=runhead)就绪队列中没有进程time+;else if(q=runhead)p=q;q=q-next;elseprintf(进程名:d
8、n,q-num);printf(到达时间:dn,q-arriveTime);if(q-rt=1)printf(响应时间:dn,time-q-arriveTime);elseprintf(第d 次运行开始时间:dn,q-rt,time); if(q-burstburst;printf(第d 次运行结束时间:dn,q-rt,time);printf(周转时间:dn,time-q-arriveTime);n);n);printf(struct pro *tmp=q;q=q-next;p-next=q;free(tmp);else /q-burstRRtime+=RR;printf(第d 次运行结束时
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 低血糖的康复训练
- 爱国卫生工作实施方案
- 高纯石墨硬毡及多孔石墨项目(一期)环境影响报告表
- 哈密土屋铜矿采矿改扩建工程环境影响报告书
- 北京师范大附属实验中学2026届初三5月单元检测试题英语试题含解析
- 山东省聊城阳谷县联考2026年中考冲刺七英语试题含解析
- 山东滕州2026届初三第二次质量调研(二模)物理试题含解析
- 安徽省巢湖市2026年初三月考试卷(三)英语试题含解析
- 浙江省宁波市海曙区三校联考2026届初三下学期第一次教学诊断英语试题含解析
- 福建省莆田市砺成中学2025-2026学年初三第三次中考模拟考试英语试题含解析
- 螺蛳粉行业技术环境分析报告
- 实物期权理论视角下汽车产业并购的价值评估与策略优化研究
- 2024北师大版七年级生物上册期末复习全册必背知识清单
- (新教材)2026年人教版一年级下册数学 第二单元 20以内的退位减法 整 理和复习 课件
- 2025新华保险总部校园招聘笔试历年参考题库附带答案详解
- 八年级数学人教版下册第十九章《二次根式》单元测试卷(含答案)
- 施工现场安全、文明考核管理办法
- 新型能源体系建设形势和展望-
- 全麻术后苏醒期护理
- 2025年公务员多省联考《申论》(云南县乡卷)题及参考答案(网友回忆版)
- 髋关节置换术后康复训练计划
评论
0/150
提交评论