【文件属性】:
文件名称:最高相应比操作系统C语言
文件大小:4KB
文件格式:CPP
更新时间:2013-12-09 16:23:34
最高相应比 操作系统
//高响应比调度算法
#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(zgxyb *p,int N)
{ int i;
for(i=0;i<=N-1;i++)
{
printf("请输入第%dth 个进程的名称:\n",i+1);
scanf("%s",&p[i].name);
printf("请输入第%dth 个进程的到达时间:\n",i+1);
scanf("%f",&p[i].arrivetime);
printf("请输入第%dth 个进程的服务时间:\n",i+1);
scanf("%f",&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("进程执行顺序:");
printf("%s",p[0].name);
for(k=1;k%s",p[k].name);
}
printf("\n进程信息:\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);
}
}
//按到达时间排序
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=p[k].arrivetime)
{
p[k].starttime=p[k-1].finishtime;}
else
{
p[k].starttime =p[k].arrivetime;}
p[k].finishtime=p[k].starttime+p[k].servicetime;
}
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=p[m].arrivetime )
{
p[m].starttime=p[m-1].finishtime;}
else
{
p[m].starttime =p[m].arrivetime;}
p[m].finishtime=p[m].starttime+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