欢迎来到天天文库
浏览记录
ID:50978713
大小:30.21 KB
页数:3页
时间:2020-03-08
《设计一个按优先数调度算法实现处理器调度的程序.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include"stdio.h"#include"malloc.h"#include"string.h"typedefstructnode{inttime;intname;charstatement;intnum;structnode*next;}node,*L;voidcreateL(L&l,intn){l=(L)malloc(sizeof(node));if(!l)printf("error!");elsel->next=NULL;Lp,q;q=l;for(inti=0;i2、p=(L)malloc(sizeof(node));printf("请输入进程的名字name:");scanf("%d",&p->name);getchar();printf("请输入该进程的运行时间time:");scanf("%d",&p->time);printf("请输入其优先级数num:");scanf("%d",&p->num);getchar();printf("请输入其状态:");p->statement=getchar();p->next=q->next;q->3、next=p;q=p;getchar();}}voidtraL(L&l){Lp;p=l->next;printf("进程名t运行时间t优先数t状态");while(p){printf("%dt%5dt%11dt%c",p->name,p->time,p->num,p->statement);printf("");p=p->next;}}voidSort(L&l){Ltail=NULL;while(tail!=l->next){Lpre=l;Lcur=pre->next;whi4、le(cur!=tail&&cur->next!=tail){if(cur->numnext->num){pre->next=cur->next;cur->next=cur->next->next;pre->next->next=cur;}pre=pre->next;cur=pre->next;}tail=cur;}}voidrun(L&l){Sort(l);Lp,r,q;q=l;if(l->next!=NULL)p=l->next;intj=0;printf("第k次运行t进程名5、t运行时间t优先数t状态");while(p!=NULL){j++;printf("%5dt%dt%5dt%11dt%c",j,p->name,p->time,p->num,p->statement);printf("");p->num--;p->time--;if(p->time==0){p->statement='E';r=p;if(p->next!=NULL){l->next=p->next;free(r);p=l->next;}elsebreak;}else{Sor6、t(l);if(l->next!=NULL)p=l->next;elsebreak;}}}voidmain(){Ll;intn;printf("请输入进程的数目n:");scanf("%d",&n);createL(l,n);traL(l);run(l);}
2、p=(L)malloc(sizeof(node));printf("请输入进程的名字name:");scanf("%d",&p->name);getchar();printf("请输入该进程的运行时间time:");scanf("%d",&p->time);printf("请输入其优先级数num:");scanf("%d",&p->num);getchar();printf("请输入其状态:");p->statement=getchar();p->next=q->next;q->
3、next=p;q=p;getchar();}}voidtraL(L&l){Lp;p=l->next;printf("进程名t运行时间t优先数t状态");while(p){printf("%dt%5dt%11dt%c",p->name,p->time,p->num,p->statement);printf("");p=p->next;}}voidSort(L&l){Ltail=NULL;while(tail!=l->next){Lpre=l;Lcur=pre->next;whi
4、le(cur!=tail&&cur->next!=tail){if(cur->numnext->num){pre->next=cur->next;cur->next=cur->next->next;pre->next->next=cur;}pre=pre->next;cur=pre->next;}tail=cur;}}voidrun(L&l){Sort(l);Lp,r,q;q=l;if(l->next!=NULL)p=l->next;intj=0;printf("第k次运行t进程名
5、t运行时间t优先数t状态");while(p!=NULL){j++;printf("%5dt%dt%5dt%11dt%c",j,p->name,p->time,p->num,p->statement);printf("");p->num--;p->time--;if(p->time==0){p->statement='E';r=p;if(p->next!=NULL){l->next=p->next;free(r);p=l->next;}elsebreak;}else{Sor
6、t(l);if(l->next!=NULL)p=l->next;elsebreak;}}}voidmain(){Ll;intn;printf("请输入进程的数目n:");scanf("%d",&n);createL(l,n);traL(l);run(l);}
此文档下载收益归作者所有