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

更新时间:2023-08-09 05:59:26 阅读: 评论:0

//高响应比调度算法
#include<stdio.h>
#include<stdlib.h>
struct zgxyb{
char name[10];
float arrivetime;
leatherettefloat rvicetime;
float starttime;
float finishtime;
float zztime;
float dqzztime;
emba学位班
};
struct zgxyb a[100];
void input(struct zgxyb*p,int N)
{int i;
printf("intput the process's name&arrivetime&rvicetime:\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].rvicetime);
}
}
void Print(struct zgxyb*p,float arrivetime,float rvicetime,float starttime,float finishtime,float zztime,float dqzztime,int N)
{int k;
printf("run order:");
printf("%s",p[0].name);
for(k=1;k<N;k++)
{printf("-->%s",p[k].name);
}
printf("\nthe process's information:\n");
printf("\nname\tarrive\trvice\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].rv 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<p[j].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 rvicetime,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].rvicetime;}
el
{
p[k].starttime=p[k-1].finishtime;
p[k].finishtime=p[k-1].finishtime+p[k].rvicetime;}
}
for(k=0;k<=N-1;k++)
{
p[k].zztime=p[k].finishtime-p[k].arrivetime;
p[k].dqzztime=p[k].zztime/p[k].rvicetime;
}
}
void ZGXYB(struct zgxyb*p,int N)
{
float arrivetime=0,rvicetime=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<N-1;m++)
{
if(m==0)
p[m].finishtime=p[m].arrivetime+p[m].rvicetime;
el
p[m].finishtime=p[m-1].finishtime+p[m].rvicetime;
用其所长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].rvicetime;amazing kanye west
full phone testfollow=m+1;
try to do
for(k=m+1;k<m+i;k++)//从第二个开始排序
{
if(max<=(p[m].finishtime-p[k+1].arrivetime)/p[k+1].rvicetime) {
max=(p[m].finishtime-p[k+1].arrivetime)/p[k+1].rvicetime;
知足常乐英文
follow=k+1;
}
}
temp=p[m+1];
p[m+1]=p[follow];
xinlei
p[follow]=temp;
}
deal(p,arrivetime,rvicetime,starttime,finishtime,zztime,dqzztime,N);
Print(p,arrivetime,rvicetime,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);
}

本文发布于:2023-08-09 05:59:26,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/192004.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:排序   调度   算法   响应
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图