您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 高响应比调度算法(C语言程序实现)
//高响应比调度算法#includestdio.h#includestdlib.hstructzgxyb{charname[10];floatarrivetime;floatservicetime;floatstarttime;floatfinishtime;floatzztime;floatdqzztime;};structzgxyba[100];voidinput(structzgxyb*p,intN){inti;printf(intputtheprocess'sname&arrivetime&servicetime:\nforexmple:a0100\n);for(i=0;i=N-1;i++){printf(inputthe%dthprocess'sinformation:\n,i+1);scanf(%s%f%f,&p[i].name,&p[i].arrivetime,&p[i].servicetime);}}voidPrint(structzgxyb*p,floatarrivetime,floatservicetime,floatstarttime,floatfinishtime,floatzztime,floatdqzztime,intN){intk;printf(runorder:);printf(%s,p[0].name);for(k=1;kN;k++){printf(--%s,p[k].name);}printf(\ntheprocess'sinformation:\n);printf(\nname\tarrive\tservice\tstart\tfinish\tzz\tdqzz\n);for(k=0;k=N-1;k++){printf(%s\t%-.2f\t%-.2f\t%-.2f\t%-.2f\t%-.2f\t%-.2f\t\n,p[k].name,p[k].arrivetime,p[k].servicetime,p[k].starttime,p[k].finishtime,p[k].zztime,p[k].dqzztime);}}//按到达时间排序voidsort(structzgxyb*p,intN){inti,j;for(i=0;i=N-1;i++)for(j=0;j=i;j++)if(p[i].arrivetimep[j].arrivetime){structzgxybtemp;temp=p[i];p[i]=p[j];p[j]=temp;}}//yunxingjieduanvoiddeal(structzgxyb*p,floatarrivetime,floatservicetime,floatstarttime,floatfinishtime,floatzztime,floatdqzztime,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].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;}}voidZGXYB(structzgxyb*p,intN){floatarrivetime=0,servicetime=0,starttime=0,finishtime=0,zztime=0,dqzztime=0;intm,i,n,follow,k;floatmax;structzgxybtemp;sort(p,N);for(m=0;mN-1;m++){if(m==0)p[m].finishtime=p[m].arrivetime+p[m].servicetime;elsep[m].finishtime=p[m-1].finishtime+p[m].servicetime;i=0;for(n=m+1;n=N-1;n++){if(p[n].arrivetime=p[m].finishtime)i++;}max=(p[m].finishtime-p[m+1].arrivetime)/p[m+1].servicetime;follow=m+1;for(k=m+1;km+i;k++)//从第二个开始排序{if(max=(p[m].finishtime-p[k+1].arrivetime)/p[k+1].servicetime){max=(p[m].finishtime-p[k+1].arrivetime)/p[k+1].servicetime;follow=k+1;}}temp=p[m+1];p[m+1]=p[follow];p[follow]=temp;}deal(p,arrivetime,servicetime,starttime,finishtime,zztime,dqzztime,N);Print(p,arrivetime,servicetime,starttime,finishtime,zztime,dqzztime,N);}voidmain(){intN;structzgxyb*c;printf(------高响应比调度算法------\n);printf(inputtheprocess'snumber:\n);scanf(%d,&N);input(a,N);c=a;ZGXYB(c,N);}
本文标题:高响应比调度算法(C语言程序实现)
链接地址:https://www.777doc.com/doc-4604774 .html