void SJF() // SJF(short job first):根据作业的运行时间从小到大依次执行 { // 1 先按到达时排序 sort(pc,pc+number,CmpByComeTime);

// 2 再按运行时排序
for(int i=0;i<number;i++){
    for(int j=i+1;j<number;j++){
        if(pc[i].run_time>pc[j].run_time && pc[i].come_time==pc[j].come_time){
            swap(pc[i],pc[j]);
        }
    }
}

// 3 计算作业的开始时间与完成时间  
get_beginAndOver_time();

// 4 计算作业的周转时间与带权周转时间  
get_roundAndAvg_time();

}

//修改部分是在SJF()函数中加入了按照运行时间排序的代码,并且是在到达时间相同时按照运行时间进行排序的

以下代码是C++实现SJF算法的但它的SJF函数存在错误希望你改正它你只需要给我改正后的SJF函数内容就可以了#include iostream #include algorithm using namespace std; #define MAXSIZE 5 作业数 int number; 用户输入的进程数量 struct process string pid;

原文地址: https://www.cveoy.top/t/topic/fava 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录