当前位置:   article > 正文

关于“用C语言实现模拟操作系统进程调度先来先服务”代码中的问题

关于“用C语言实现模拟操作系统进程调度先来先服务”代码中的问题


代码如下,其中从for循环开始,至函数截止所表达的意思和作用我不太明白,求大神尽快解答!!!麻烦了,谢谢!!!

float response_ratio(jobtable job[],int n)/*模拟当前作业表的调度过程*/
 {   int i,j,temp;
     float average_time,ratio1,ratio2;
     job[0].begin_run=job[0].in_well;
     job[0].end_run=job[0].begin_run+job[0].run_time;
     job[0].turnover_time=job[0].end_run-job[0].begin_run;
     average_time=job[0].turnover_time;
     for(i=1;i<n;i++)
     {  if(job[i].in_well<=job[i-1].end_run)
        {  j=i+1;temp=i;
           ratio1=1+(job[i-1].end_run-job[i].in_well)*1.0/job[i].run_time;
           while(j<n&&job[j].in_well<=job[i-1].end_run)
           { 
              ratio2=1+(job[i-1].end_run-job[j].in_well)*1.0/job[j].run_time;
              if(ratio2>ratio1)  temp=j;
              j++;
           }
           if(temp!=i) 
              swap(job,i,temp);
        }
      job[i].begin_run=job[i-1].end_run;
      job[i].end_run=job[i].begin_run+job[i].run_time;
      job[i].turnover_time=job[i].end_run-job[i].in_well;
      average_time=average_time+job[i].turnover_time;
    }
    return(average_time/n);
 }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/964643
推荐阅读
相关标签
  

闽ICP备14008679号