资源描述:
《C语言实现短作业优先调度算法.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include"stdio.h"structsjf{charname[10];floatarrivetime;floatservicetime;floatstarttime;floatfinishtime;floatzztime;floatdqzztime;floatcckj;floatyxtime;};sjfa[100];voidinput(sjf*p,intN){inti;printf("输入作业名&到达时间&服务时间&存储空间:例如:a010033");for(i=0;i<=N-1;i++){printf("输入第%d作业信息:",
2、i+1);scanf("%s%f%f%f",&p[i].name,&p[i].arrivetime,&p[i].servicetime,&p[i].cckj);}}voidPrint(sjf*p,floatarrivetime,floatservicetime,floatstarttime,floatfinishtime,floatzztime,floatdqzztime,floatcckj,intN){intk;printf("作业执行顺序:");printf("%s",p[0].name);for(k=1;k%
3、s",p[k].name);}printf("作业信息:");printf("nametarrivetservicetstarttfinishtzztdqzztcckjtddsjtyxtime");for(k=0;k<=N-1;k++){printf("%st%-.2ft%-.2ft%-.2ft%-.2ft%-.2ft%-.2ft%-.2ft%-.2ft%-.2f",p[k].name,p[k].arrivetime,p[k].servicetime,p[k].starttime,p[k].fin
4、ishtime,p[k].zztime,p[k].dqzztime,p[k].cckj,p[k].finishtime-p[k].servicetime,p[k].servicetime);}}//paixuvoidsort(sjf*p,intN){for(inti=0;i<=N-1;i++)for(intj=0;j<=i;j++)if(p[i].arrivetime
5、arrivetime,floatservicetime,floatstarttime,floatfinishtime,float&zztime,float&dqzztime,floatcckj,intN){intk;for(k=0;k<=N-1;k++){if(k==0){p[k].starttime=p[k].arrivetime;p[k].finishtime=p[k].arrivetime+p[k].servicetime;}else{p[k].starttime=p[k-1].finishtime;p[k].finishtime=p[k-1].
6、finishtime+p[k].servicetime;}}for(k=0;k<=N-1;k++){p[k].zztime=p[k].finishtime-p[k].arrivetime;p[k].dqzztime=p[k].zztime/p[k].servicetime;}}voidsjff(sjf*p,intN){floatarrivetime=0,servicetime=0,starttime=0,finishtime=0,zztime=0,dqzztime=0,cckj=0;sort(p,N);for(intm=0;m7、m==0)p[m].finishtime=p[m].arrivetime+p[m].servicetime;elsep[m].finishtime=p[m-1].finishtime+p[m].servicetime;inti=0;for(intn=m+1;n<=N-1;n++){if(p[n].arrivetime<=p[m].finishtime)i++;}floatmin=p[m+1].servicetime;intnext=m+1;//m+1=nfor(intk=m+1;k8、{min=p[k+1].servicetime;next=k+1;}}sjftemp;temp