高响应比调度算法(C语言程序实现)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

//高响应比调度算法

#include

#include

struct zgxyb{

char name[10];

float arrivetime;

float servicetime;

float starttime;

float finishtime;

float zztime;

float dqzztime;

};

struct zgxyb a[100];

void input(struct zgxyb*p,int N)

{int i;

printf("intput the process's name&arrivetime&servicetime:\nfor exmple:a0100\n");

for(i=0;i<=N-1;i++)

{

printf("input the%dth process's information:\n",i+1);

scanf("%s%f%f",&p[i].name,&p[i].arrivetime,&p[i].servicetime);

}

}

void Print(struct zgxyb*p,float arrivetime,float servicetime,float starttime,float finishtime,float zztime,float dqzztime,int N)

{int k;

printf("run order:");

printf("%s",p[0].name);

for(k=1;k

{printf("-->%s",p[k].name);

}

printf("\nthe process's information:\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].serv icetime,p[k].starttime,p[k].finishtime,p[k].zztime,p[k].dqzztime);

}

}

//按到达时间排序

void sort(struct zgxyb*p,int N)

{

int i,j;

for(i=0;i<=N-1;i++)

for(j=0;j<=i;j++)

if(p[i].arrivetime

{

struct zgxyb temp;

temp=p[i];

p[i]=p[j];

p[j]=temp;

}

}

//yun xing jieduan

void deal(struct zgxyb*p,float arrivetime,float servicetime,float starttime,float finishtime,float zztime,float dqzztime,int N)

{int k;

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;

}

}

void ZGXYB(struct zgxyb*p,int N)

{

float arrivetime=0,servicetime=0,starttime=0,finishtime=0,zztime=0,dqzztime=0;

int m,i,n,follow,k;

float max;

struct zgxyb temp;

sort(p,N);

for(m=0;m

{

if(m==0)

p[m].finishtime=p[m].arrivetime+p[m].servicetime;

else

p[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;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); }

void main()

{int N;

struct zgxyb*c;

printf("------高响应比调度算法------\n");

printf("input the process's number:\n");

scanf("%d",&N);

input(a,N);

c=a;

ZGXYB(c,N);

}

相关文档
最新文档