《短作业优先调度算法》由会员分享,可在线阅读,更多相关《短作业优先调度算法(5页珍藏版)》请在金锄头文库上搜索。
1、短作业优先调度算法短作业优先调度算法#include “stdio.h“struct sjfchar name10;float arrivetime;float servicetime;float starttime;float finishtime;float zztime;float dqzztime;sjf a100;void input(sjf *p,int N) int i;printf(“intput the processs name for(i=0;i%s“,pk.name); printf(“nthe processs information:n“);printf(“nnam
2、etarrivetservicetstarttfinishtzztdqzzn“);for(k=0;k=N-1;k+) printf(“%st%-.2ft%-.2ft%-.2ft%-.2ft%-.2ft%-.2ftn“,pk.name,pk.arrivetime,pk.servicetime,pk.starttime,pk.finishtime,pk.zztime,pk.dqzztime);/pai xuvoid sort(sjf *p,int N)for(int i=0;i=N-1;i+)for(int j=0;j=i;j+)if(pi.arrivetimepj.arrivetime)sjf
3、temp;temp=pi;pi=pj;pj=temp;/yun xing jieduanvoid deal(sjf *p, float arrivetime,float servicetime,float starttime,float finishtime,float for(k=0;k=N-1;k+)if(k=0) pk.starttime=pk.arrivetime;pk.finishtime=pk.arrivetime+pk.servicetime;elsepk.starttime=pk-1.finishtime;pk.finishtime=pk-1.finishtime+pk.ser
4、vicetime;for(k=0;k=N-1;k+)pk.zztime=pk.finishtime-pk.arrivetime;pk.dqzztime=pk.zztime/pk.servicetime;void sjff(sjf *p,int N)float arrivetime=0,servicetime=0,starttime=0,finishtime=0,zztime=0,dqzztime=0;sort(p,N);for(int m=0;mN-1;m+)if(m=0)pm.finishtime=pm.arrivetime+pm.servicetime;elsepm.finishtime=
5、pm-1.finishtime+pm.servicetime;int i=0;for(int n=m+1;n=N-1;n+)if(pn.arrivetime=pm.finishtime)i+;float min=pm+1.servicetime;int next=m+1;/m+1=nfor(int k=m+1;km+i;k+)if(pk+1.servicetimemin)min=pk+1.servicetime;next=k+1;sjf temp;temp=pm+1;pm+1=pnext;pnext=temp;deal(p,arrivetime,servicetime,starttime,finishtime,zztime,dqzztime,N);Print(p,arrivetime,servicetime,starttime,finishtime,zztime,dqzztime,N);void main() int N;printf(“-短作业优先调度算法-n“);printf(“input the processs number:n“);scanf(“%d“,input(a,N);sjf *b=a;sjf *c=a;sjff(b,N);