Java時間片輪轉(簡單模擬實現,適合初學者)

2021-08-20 04:56:12 字數 1368 閱讀 3177

package 排程演算法2;//注意檔名,需與自己建立的一致  

public class shijianpian ;

for(int i=0;isystem.out.println();

int a= ,,,}; //建立並輸出資料 。注意賦值時按照到達時間由短到長排序

for(int j=0;jsystem.out.println();

}

int nt=0;//nt才是真正的時間!!!!!!

int nt1=0,nt2=0,nt3=0,nt4=0;//記錄執行時間

int ci=0;//記錄已經執行多少個程序

int sh=0;//初始化方法的返回值

for(int t=0;t<=30;t++) catch (interruptedexception e2)

nt=nt+1;//時間增加1個時間片

nt1=nt1+1;//記錄執行時間

}if(nt1==a[0][2] && a1==1)

sh=name(a[0][1],a[1][1],a[2][1],a[3][1],nt);//2

if(b1==1) catch (interruptedexception e2)

b1=1;

nt=nt+1;

nt2=nt2+1;

}if(nt2==a[1][2] && b1==1)

sh=name(a[0][1],a[1][1],a[2][1],a[3][1],nt);//3

if(c1==1) catch (interruptedexception e2)

nt=nt+1;

nt3=nt3+1;

}if(nt3==a[1][2] && c1==1)

sh=name(a[0][1],a[1][1],a[2][1],a[3][1],nt);//4

if(d1==1) catch (interruptedexception e2)

nt=nt+1;

nt4=nt4+1;

}if(nt4==a[3][2] && d1==1)

if(a1==0 && b1==0 && c1==0 && d1==0) catch (interruptedexception e2)

nt=nt+1;

} if(ci == a[3][0])

} }

public static int name(int a,int b,int c,int d,int nt)//自定義的求階乘的函式

if(b==nt)

if(c==nt)

if(d==nt)

return 0;

} }

時間片輪轉排程演算法的C語言模擬實現

時間片輪轉排程 是一種最古老,最簡單,最公平且使用最廣的演算法。每個程序被分配乙個時間段,稱作它的時間片,即該程序允許執行的時間。如果在時間片結束時程序還在執行,則cpu將被剝奪並分配給另乙個程序。如果程序在時間片結束前阻塞或結束,則cpu當即進行切換。以下是c演算法的模擬實現 include de...

時間片輪轉演算法實現

include include define null 0 typedef struct quen 定義結構 char pname 8 int time1 int time2 char state struct quen next quen main 主程式 quen q,p,head,m char...

時間片輪轉演算法實現

程式設計實現時間片輪轉演算法,並求出每個作業的完成時間 周轉時間 帶權周轉時間,及平均周轉時間 平均帶權周轉時間。任選一種高階語言實現 選擇1 2種排程演算法 能夠輸入程序的基本資訊,如程序名 提交時間 預估執行時間等 根據選擇的排程演算法顯示程序排程順序 顯示完成排程後每個程序的開始時間 完成時間...