3、);scanf("%s",p->name);printf("輸入作業(yè)所需時間:");scanf("%d",&p->ntime);printf("");p->atime=i;p->state='w';p->link=NULL;sort();/調(diào)用sort函數(shù)/}}intspace(){intl=0;JCBpr=ready;while(pr!=NULL){l++;pr=pr->link;}return(l);}disp1(JCBpr)/建立作業(yè)顯示函數(shù),用于顯示當(dāng)前作業(yè)/{printf("作業(yè)名狀態(tài)開始時刻完成
4、時刻周轉(zhuǎn)時間帶權(quán)周轉(zhuǎn)時間");printf("%st",pr->name);printf("%ct",pr->state);printf("%dt",pr->stime);printf("%dt",pr->ctime);printf("%dt",pr->ttime);printf("%ft",pr->bttime);printf("");}disp2(JCBpr)/建立進(jìn)程顯示函數(shù),用于顯示當(dāng)前進(jìn)程/{printf("作業(yè)名狀態(tài)到達(dá)時刻所需時間");printf("%st",pr->nam
5、e);printf("%ct",pr->state);printf("%dt",pr->atime);printf("%dt",pr->ntime);printf("");}check()/建立作業(yè)查看函數(shù)/{JCBpr;pr=ready;printf("當(dāng)前就緒隊(duì)列狀態(tài)為:");/顯示就緒隊(duì)列狀態(tài)/while(pr!=NULL){disp2(pr);pr=pr->link;}}destroy()/建立作業(yè)撤消函數(shù)(作業(yè)運(yùn)行結(jié)束,撤消作業(yè))/{printf("作業(yè)[%s]已完成.",p->na
6、me);free(p);}running(){p->stime=wtime;p->ctime=p->stime+p->ntime;p->ttime=p->ctime-p->atime;p->bttime=(float)p->ttime/(float)p->ntime;wtime=wtime+p->ntime;/printf("時間:%f",wtime);/wttime=wttime+p->ttime;wbttime=wbttime+p->bttime;printf("當(dāng)前正在運(yùn)行的作業(yè)是:%s",p->name);
7、/顯示當(dāng)前運(yùn)行作業(yè)/disp1(p);destroy();}main()/主函數(shù)/{intlen,h=0;charch;input();len=space();while((len!=0)&&(ready!=NULL)){ch=getchar();h++;printf("Theexecutenumber:%d",h);p=ready;ready=p->link;p->link=NULL;p->state='R';running();check();printf("按任一鍵繼續(xù)......");ch=getc
8、har();}printf("作業(yè)已經(jīng)完成.");printf("該次作業(yè)調(diào)度平均周轉(zhuǎn)時間:%f",wttime/len);printf("該次作業(yè)調(diào)度帶權(quán)平均周轉(zhuǎn)時間:%f",wbttime/len);ch=getchar();}