欢迎来到天天文库
浏览记录
ID:9391076
大小:42.50 KB
页数:7页
时间:2018-04-29
《最高优先数优先算法》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#includestructPCB{charp_name[20];intp_priority;intp_needTime;intp_runTime;charp_state;structPCB*next;};voidHighPriority();voidRoundRobin();voidInformation();charChoice();structPCB*SortList(PCB*HL);intmain(){Information();charchoice=Choice();switch(choice){case'1':system("
2、cls");HighPriority();break;default:break;}system("pause");return0;}voidInformation(){printf("");printf("*********************************************");printf("模拟进程调度算法");printf("*********************************************");printf("按回车键进入演示程序");getchar();system("cls");}charChoice()
3、{printf("");printf("*********************************************");printf("进程调度演示");printf("*********************************************");printf("1.演示最高优先数优先算法。");printf("3.退出程序。");printf("选择进程调度方法:");charch=getchar();returnch;system("cls");}voidHighPriority(){structPCB*p
4、rocesses,*pt;//pt作为临时节点来创建链表processes=pt=(structPCB*)malloc(sizeof(structPCB));for(inti=0;i!=3;++i){structPCB*p=(structPCB*)malloc(sizeof(structPCB));printf("进程号No.%d:",i);printf("输入进程名:");scanf("%s",p->p_name);printf("输入进程优先数:");scanf("%d",&p->p_priority);printf("输入进程运行时间:");scanf("%d",&p->p_nee
5、dTime);p->p_runTime=0;p->p_state='W';p->next=NULL;pt->next=p;pt=p;printf("");}getchar();//接受回车//processes作为头结点来存储链表processes=processes->next;intcases=0;structPCB*psorted=processes;while(1){++cases;pt=processes;//对链表按照优先数排序//psorted用来存放排序后的链表psorted=SortList(psorted);printf("Theexecutenumber:%d
6、n",cases);printf("****当前正在运行的进程是:%s",psorted->p_name);psorted->p_state='R';printf("qnamestatesuperndtimeruntime");printf("%st%ct%dt%dt%dt",psorted->p_name,psorted->p_state,psorted->p_priority,psorted->p_needTime,psorted->p_runTime);pt->p_state='W';psorted->p_runTime++;psorted->p_prio
7、rity--;printf("****当前就绪状态的队列为:");//pt指向已经排序的队列pt=psorted->next;while(pt!=NULL){printf("qnamestatesuperndtimeruntime");printf("%st%ct%dt%dt%dt",pt->p_name,pt->p_state,pt->p_priority,pt->p_need
此文档下载收益归作者所有