版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上非抢占短作业优先算法源代码(C语言) #include <stdio.h>#include <stdlib.h>#define MAX 5 /进程数/*短作业优先算法*/struct proint num; /进程名int arriveTime; /到达时间int burst; /运行时间;struct pro *next;/函数声明struct pro* creatList();void insert(struct pro *head,struct pro *s); struct pro* searchByAT
2、(struct pro *head,int AT); void run(struct pro *head);void del(struct pro* p);int getCount(struct pro *head,int time);struct pro* creatList() /创建链表,按照进程的到达时间排列struct pro* head=(struct pro*)malloc(sizeof(struct pro);head->next=NULL;struct pro* s;int i;for(i=0;i<MAX;i+)s=(struct pro*)mal
3、loc(sizeof(struct pro);printf("请输入进程名:n");scanf("%d",&(s->num);printf("请输入到达时间:n");scanf("%d",&(s->arriveTime);printf("请输入运行时间:n");scanf("%d",&(s->
4、burst);s->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->next=s;return;struct pro* searchByAT(struct pro *head,int AT) /查找第一个到达时间大于等于AT的节点,返回其前一个指针struct pro *p,*
5、q;p=head;q=head->next;while(q!=NULL&&q->arriveTime<=AT)p=q;q=q->next;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) /察看当前就绪队列中的进程数int co
6、unt=0;struct pro *p,*q;p=head;q=p->next;while(q!=NULL&&q->arriveTime<=time)count+;p=q;q=q->next;return count;struct pro* SJF(struct pro *head,int count) /在头节点后的count个节点中选择burst最小的,返回其前一个节点的指针int min;struct pro *p,*q,*flag;p=head;q=p->next;min=q-&
7、;gt;burst;flag=p; /flag记录返回指针while(count>0)if(q->burst<min)min=q->burst;flag=p;count-;p=q;q=q->next;return flag;void run(struct pro *head) /按短作业优先算法调度进程,并输出其运行情况int time=0,count;struct pro *s,*t;while(head->next!=NULL)count=getCount(head,time);if(count=0) /如
8、果当前就绪队列中没有进程,时间自增time+;else if(count=1) /如果就绪队列中只有1个进程,则必定是第一个节点t=head;s=t->next;printf("进程名:%dn",s->num);printf("到达时间:%dn",s->arriveTime);printf("运行开始时间:%dn",time);printf("响应时间:%dn",time-s->arriveTim
9、e);time+=s->burst;printf("运行结束时间:%dn",time);printf("周转时间:%dn",time-s->arriveTime);printf("*n");del(t );else /如果就绪队列中的进程数>=2,则在head后的count个节点中进行短作业优先调度t=SJF(head,count);s=t->next;printf("进程名:%dn",s->num);printf("到达时间:%dn",s->arriveTime);printf("运行开始时间:%dn",time);printf("响应时间:%dn",time-s->arriveTime);time+=s->burst;printf("运行结束时间:%dn",time);printf("周转时间:%dn",time-s-&g
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 医院污水站故障应急处置预案
- 便民服务大厅自助设备故障整改方案
- 2026年安全知识考试试题及答案
- 厂区消防通道占用常态化管控整改措施
- 2026煤矿高级技师试题及答案
- 国有企业职称评审管理办法
- 2026国家司法考试模拟试题及答案
- 名人励志高考故事演讲稿
- 火灾原因认定暂行规则课件
- 有关同事关系的演讲稿
- 第15课 规划与设计教学设计-2025-2026学年小学信息技术(信息科技)五年级第5册滇人版
- DBJ50T-542-2026 建筑机器人应用技术标准
- 1.2 1.2.1 命题与量词 课件-2026版高中数学人教B版必修第一册
- 2025版煤矿安全规程题库645道
- 农行笔试真题全套及答案
- 部编版初一语文七年级上册《咏雪》听评课记录(区公开课)
- 塑胶件培训课件
- 高中数学第九、十章统计与概率章节测试卷-2024-2025学年高一下学期数学人教A版(2019)必修第二册
- 特殊工艺过程管理制度
- CJ/T 355-2010小型生活污水处理成套设备
- 部编版高考默写60篇《将进酒》挖空实词释义及理解性默写
评论
0/150
提交评论