資源描述:
《FCFS先來先服務(wù)算法SPN短進(jìn)程優(yōu)先算法RR時間片輪轉(zhuǎn)算法》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、以下算法本人全是在vs2003環(huán)境下搞定的,望采納先來先服務(wù)算法:#include#includetypedefstructprocess_FCFS{charname[15];//進(jìn)程名floatarrivetime;//到達(dá)時間floatservetime;//服務(wù)時間floatfinishtime;//完成時間floatroundtime;//周轉(zhuǎn)時間floatdaiquantime;//帶權(quán)周轉(zhuǎn)時間structprocess_FCFS*link;//結(jié)構(gòu)體指針}FCFS;FCFS*p,*q,*head=
2、NULL;structprocess_FCFSa[100];FCFSinital(structprocess_FCFSa[],intn);voidprint(structprocess_FCFSa[],intn);voidFcfs(structprocess_FCFSa[],intn);structprocess_FCFS*sortarrivetime(structprocess_FCFSa[],intn);//按到達(dá)時間進(jìn)行冒泡排序structprocess_FCFS*sortarrivetime(structprocess_FCFSa[],i
3、ntn){inti,j;structprocess_FCFSt;intflag;for(i=1;ia[j+1].arrivetime){t=a[j];a[j]=a[j+1];a[j+1]=t;flag=1;//交換}}if(flag==0)//如果一趟排序中沒發(fā)生任何交換,則排序結(jié)束break;}returna;}//先來先服務(wù)算法voidFcfs(structprocess_FCFSa[],intn){inti;a[0].finishtim
4、e=a[0].arrivetime+a[0].servetime;a[0].roundtime=a[0].finishtime-a[0].arrivetime;a[0].daiquantime=a[0].roundtime/a[0].servetime;for(i=1;i5、e;a[i].daiquantime=a[i].roundtime/a[i].servetime;}else{a[i].finishtime=a[i].arrivetime+a[i].servetime;a[i].roundtime=a[i].finishtime-a[i].arrivetime;a[i].daiquantime=a[i].roundtime/a[i].servetime;}}printf("先來先服務(wù)");print(a,n);}voidprint(structprocess_FCFSa[],intn){inti;for(i
6、=0;i7、%d",&n);for(i=0;i8、行冒泡排序structprocess_FCFS*sortarrivetime(structprocess_FCFSa[],intn){i