ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:17KB ,
资源ID:10650410      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10650410.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(先来先服务短作业优先时间片轮转高优先权算法.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

先来先服务短作业优先时间片轮转高优先权算法.docx

1、先来先服务短作业优先时间片轮转高优先权算法#include#define N 4#include /时间片系列#include#include#define MAX 4 /进程数量#define RR 4 /时间片大小/时间片系列using namespace std;struct time string name; float arriveTime; float runTime; float finishTime; float totalTime; float weightTotalTime; ;/时间片系列struct prochar num;int arriveTime;int burs

2、t;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 pro* p);int getCount(struct pro *head,int time);struct pro* searchEnd(struct pro *head);void

3、move(struct pro *headF,struct pro *headT,int n);struct pro* creatList() /创建链表,按照进程的到达时间排列,记录所有进程的信息struct pro* head=(struct pro*)malloc(sizeof(struct pro);head-next=NULL; struct pro* s;int i;TOTALTIME=0;cout输入进程名 & 到达时间 & 运行时间(example:a 0 0):endl; coutname arrivetime runtimeendl;for(i=0;is-num; cins

4、-arriveTime; cins-burst; TOTALTIME+=s-burst; /计算总时间 s-rt=1; /rt的初始值为1 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

5、 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) /察看在time之前到达但未移动到运行队列的进程数量int count=0;struct pro *s,*t;s=

6、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,struct pro *headT,int n) /将headF后的n个节点移动到循环队列hea

7、dT中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);if(s!=headT)s=s-next;t-next=s-next;s-next=r;struct pro *f=s;void run(struct pro *head)int time=0; /记录当前时间int newarrive;/新到达进程数struct pro *runhead=(struc

8、t 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个节点移动到runhead队列中 if(runhead-next=runhead) /就绪队列中没有进程 time+; else if(q=runhead) p=q; q=q-next; else cout进程名:numen

9、dl; cout到达时间:arriveTimert=1) printf(响应时间:%dn,time-q-arriveTime); else printf(第%d次运行开始时间:%dn,q-rt,time); if(q-burstburst; printf(第%d次运行结束时间:%dn,q-rt,time); printf(周转时间:%dn,time-q-arriveTime); printf(*n); struct pro *tmp=q; q=q-next; p-next=q; runhead-next=q; free(tmp); else /q-burstRR time+=RR; print

10、f(第%d次运行结束时间:%dn,q-rt,time); printf(*n); q-burst-=RR; q-rt+; struct pro *h; h=runhead-next; if(h-next!=runhead) while(h-next!=runhead) h=h-next; runhead-next=q-next; h-next=q;q-next=runhead; q=runhead-next; else struct pro *n; n=q; p=q; q=q-next; /时间片系列 void InputTime(time *p) int i;/counter coutinp

11、ut name & arrive time & run time(example:a 0 0):endl;coutname arrivetime runtimeendl; for(i=0;iname; pi.name=name; cintemp1; pi.arriveTime=temp1; cintemp2; pi.runTime=temp2; void Print(time *p,float totalTimeSum,float weightTotalTimeSum) cout*运行次序:endl; for(int k=0;k=N-1;k+) coutpk.name ; coutendl;

12、cout平均周转时间:totalTimeSum/Nendl; cout平均带权周转时间:weightTotalTimeSum/Nendl; void sort(time *p) for(int i=0;i=N-1;i+) for(int j=0;j=i;j+) if(pi.arriveTimepj.arriveTime) time temp; temp=pi; pi=pj; pj=temp; void deal(time *p,float &totalTimeSum,float &weightTotalTimeSum) int k;/counter for(k=0;k=N-1;k+) if(k

13、=0) pk.finishTime=pk.arriveTime+pk.runTime; else pk.finishTime=pk-1.finishTime+pk.runTime; for(k=0;k=N-1;k+) pk.totalTime=pk.finishTime-pk.arriveTime; pk.weightTotalTime=pk.totalTime/pk.runTime; totalTimeSum+=pk.totalTime; weightTotalTimeSum+=pk.weightTotalTime; void FCFS(time *p) float totalTimeSum

14、=0,weightTotalTimeSum=0; sort(p); deal(p,totalTimeSum,weightTotalTimeSum); coutendl; cout*endl; cout*先来先服务:endl;Print(p,totalTimeSum,weightTotalTimeSum);cout*endl; void SWF(time *p) float totalTimeSum=0,weightTotalTimeSum=0; sort(p); for(int m=0;mN-1;m+) if(m=0) pm.finishTime=pm.arriveTime+pm.runTim

15、e; else pm.finishTime=pm-1.finishTime+pm.runTime; int i=0; for(int n=m+1;n=N-1;n+) if(pn.arriveTime=pm.finishTime) i+; float min=pm+1.runTime; int follow=m+1; for(int k=m+1;km+i;k+) if(pk+1.runTimemin) min=pk+1.runTime; follow=k+1; time temp; temp=pm+1; pm+1=pfollow; pfollow=temp; deal(p,totalTimeSu

16、m,weightTotalTimeSum); coutendl; cout*endl; cout*短作业优先:endl; Print(p,totalTimeSum,weightTotalTimeSum);cout*endl;void TRRF(time *p) float totalTimeSum=0,weightTotalTimeSum=0; sort(p); for(int m=0;mN-1;m+) if(m=0) pm.finishTime=pm.arriveTime+pm.runTime; else pm.finishTime=pm-1.finishTime+pm.runTime; i

17、nt i=0; for(int n=m+1;n=N-1;n+) if(pn.arriveTime=pm.finishTime) i+; float max=(pm.finishTime-pm+1.arriveTime)/pm+1.runTime; int follow=m+1; for(int k=m+1;km+i;k+) if(max=(pm.finishTime-pk+1.arriveTime)/pk+1.runTime) max=(pm.finishTime-pk+1.arriveTime)/pk+1.runTime; follow=k+1; time temp; temp=pm+1;

18、pm+1=pfollow; pfollow=temp; deal(p,totalTimeSum,weightTotalTimeSum); coutendl;cout*endl; cout*最高响应比优先:endl; Print(p,totalTimeSum,weightTotalTimeSum);cout*endl; void main() int lg; cout请选择任一种算法:endl; cout1.FCFS(先来先服务) 2.SWF(短作业优先) 3.TRRF(高响应比优先) 4.RR(时间片轮转) 0.退出lg;coutendl; time aN,bN,cN; while (lg)

19、if(lg=1) InputTime(a); FCFS(a); coutendl; /time *b=a;time *c=a; if(lg=2) InputTime(b); SWF(b); coutendl; if(lg=3) InputTime(c); TRRF(c); coutendl; /时间片系列 if(lg=4) coutendl; cout*时间片模拟*endl;struct pro *head=creatList();printf(当前时间片大小为:%dn,RR);run(head); coutendl; cout1.FCFS(先来先服务) 2.SWF(短作业优先) 3.TRRF(高响应比优先) 4.RR(时间片轮转) 0.退出lg; coutendl; cout您选择了退出模拟。endl;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1