}
//按到达时间排序
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() { printf(\ ------------------欢迎您使用本系统---------------\\n\ printf(\ --------------12软工3班 陈宇锋 谈泽宇------------\\n\printf(\ -- 1 使用短作业优先算法 --\\n\int option; printf(\ -- 2 使用时间片轮转算法 --\\n\ printf(\ -- 3 使用先来先服务算法 --\\n\ printf(\ -- 4 使用静态优先权优先算法 --\\n\ printf(\ -- 5 使用高响应比调度算法 --\\n\ printf(\ -- 0 退出 --\\n\printf(\ -------------------------------------------------\\n\ scanf(\switch(option) { case 0: printf(\运行结束。\\n\break; case 1: printf(\ --------------12软工3班 陈宇锋 谈泽宇------------\\n\ printf(\ 短作业优先调度算法模拟 \\n\ printf(\ ----------------------------------------------\\n\ Pinput(); SJF(); sh: Poutput(); break; case 2: printf(\ --------------欢迎使用时间片轮转算法------------\\n\ printf(\请输入要创建的进程数目:\\n\ scanf(\ TimeCreate(); RoundRun(); Output(); break; case 3: printf(\ --------------12软工3班 陈宇锋 谈泽宇------------\\n\ printf(\ 先来先服务算法模拟 \\n\ printf(\ ----------------------------------------------\\n\ getInfo(); p=head1; fcfs(); break; case 4: Menu(); break; case 5: printf(\ --------------12软工3班 陈宇锋 谈泽宇------------\\n\ printf(\ ------------------高响应比调度算法---------------\\n\ printf(\ ----------------------------------------------\\n\ printf(\输入进程的个数:\\n\ scanf(\ input(a,N); c=a; ZGXYB(c,N); break; } }