我正在尝试实现循环调度算法.但到目前为止我所做的代码只考虑了突发时间.我也需要考虑这个过程的到达时间.我有一个time_chart数组,我用它来存储当前正在执行的进程的编号.但是如果当前没有进程正在执行(即如果所选进程已完成执行并且下一个进程尚未到达.),则应将值0插入time_chart数组中.
我将突发时间和到达时间存储在2D数组中:
//proc[][0] is the AT array
//proc[][1] is the BT array
Run Code Online (Sandbox Code Playgroud)
和变量q中的时间量子.以下是我的代码:
int time_chart[] = new int[total_time];
int sel_proc = 1;
int current_q = 0;
for (int k = 0; k < total_time; k++) {
//Assign selected process to current time in the Chart
time_chart[k] = sel_proc;
//Decrement Remaining Time of selected process by 1 since it has been assigned the CPU for 1 unit of time
proc[sel_proc - 1][1]--;
//Updating value of sel_proc for next iteration
current_q++;
if …Run Code Online (Sandbox Code Playgroud)