欢迎来到天天文库
浏览记录
ID:38581358
大小:187.00 KB
页数:9页
时间:2019-06-15
《FCFS先来先服务算法SPN短进程优先算法RR时间片轮转算法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、以下算法本人全是在vs2003环境下搞定的,望采纳先来先服务算法:#include#includetypedefstructprocess_FCFS{charname[15];//进程名floatarrivetime;//到达时间floatservetime;//服务时间floatfinishtime;//完成时间floatroundtime;//周转时间floatdaiquantime;//带权周转时间structprocess_FCFS*link;//结构体指针}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);//按到达时间进行冒泡排序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)//如果一趟排序中没发生任何交换,则排序结束break;}returna;}//先来先服务算法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("先来先服务");print(a,n);}voidprint(structprocess_FCFSa[],intn){inti;for(i6、=0;i7、%d",&n);for(i=0;i8、行冒泡排序structprocess_FCFS*sortarrivetime(structprocess_FCFSa[],intn){i
5、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("先来先服务");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
7、%d",&n);for(i=0;i8、行冒泡排序structprocess_FCFS*sortarrivetime(structprocess_FCFSa[],intn){i
8、行冒泡排序structprocess_FCFS*sortarrivetime(structprocess_FCFSa[],intn){i
此文档下载收益归作者所有