




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include #include struct PCB char p_name20; int p_priority; int p_needTime; int p_runTime; char p_state; struct PCB* next;void HighPriority();void RoundRobin();void Information();char Choice();struct PCB* SortList(PCB* HL);int main() Information(); char choice = Choice(); switch(choice) case 1: system(cls); HighPriority(); break; default: break; system(pause); return 0;void Information() printf(nn); printf( * n); printf( 模拟进程调度算法n); printf( * nnn); printf( 按回车键进入演示程序); getchar(); system(cls);char Choice() printf(nn); printf( * n); printf( 进程调度演示n); printf( * nnn); printf( 1.演示最高优先数优先算法。n); printf( 3.退出程序。nnnn); printf( 选择进程调度方法:); char ch = getchar(); return ch; system(cls);void HighPriority() struct PCB *processes, *pt; /pt作为临时节点来创建链表 processes = pt = (struct PCB*)malloc(sizeof(struct PCB); for (int i = 0; i != 3; +i) struct PCB *p = (struct PCB*)malloc(sizeof(struct PCB); printf(进程号No.%d:n, i); printf(输入进程名:); scanf(%s, p-p_name); printf(输入进程优先数:); scanf(%d, &p-p_priority); printf(输入进程运行时间:); scanf(%d, &p-p_needTime); p-p_runTime = 0; p-p_state = W; p-next = NULL; pt-next = p; pt = p; printf(nn); getchar(); /接受回车 /processes作为头结点来存储链表 processes = processes-next; int cases = 0; struct PCB *psorted = processes; while (1) +cases; pt = processes; /对链表按照优先数排序 /psorted用来存放排序后的链表 psorted = SortList(psorted); printf(The execute number: %dnn, cases); printf(* 当前正在运行的进程是:%sn, psorted-p_name); psorted-p_state = R; printf(qname state super ndtime runtimen); printf(%st%ct%dt%dt%dtnn, psorted-p_name, psorted-p_state, psorted-p_priority, psorted-p_needTime, psorted-p_runTime); pt-p_state = W; psorted-p_runTime+; psorted-p_priority-; printf(* 当前就绪状态的队列为:nn); /pt指向已经排序的队列 pt = psorted-next; while (pt != NULL) printf(qname state super ndtime runtimen); printf(%st%ct%dt%dt%dtnn, pt-p_name, pt-p_state, pt-p_priority, pt-p_needTime, pt-p_runTime); pt = pt-next; /pt指向已经排序的链表,判断链表是否有已用时间啊等于需要时间的 pt = psorted; struct PCB *ap; ap = NULL; /ap指向pt的前一个节点 while (pt != NULL) if (pt-p_needTime = pt-p_runTime) if (ap = NULL) pt = psorted-next; psorted = pt; else ap-next = pt-next; ap = pt; pt = pt-next; if (psorted-next = NULL) break; getchar(); struct PCB* SortList(PCB* HL) struct PCB* SL; SL = (struct PCB*)malloc(sizeof(struct PCB); SL = NULL; struct PCB* r = HL; while (r != NULL) struct PCB* t = r-next; struct PCB* cp = SL; struct PCB* ap = NULL; while (cp != NULL) if (r-p_priority cp-p_pri
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 河北省石家庄市高邑县2023-2024学年五年级下学期数学7月期末试卷(含答案)
- 仲夏美食活动策划方案
- 企业下午茶活动方案
- 企业上市答谢活动方案
- 企业以物换物活动方案
- 企业公司五四活动方案
- 企业减压活动方案
- 企业参加默哀活动方案
- 企业商业团建活动方案
- 企业夏季活动方案
- 家具厂客户投诉处理手册
- 2024年化学水处理工(技师)技能鉴定理论考试题库(含答案)
- 贵州省贵阳市2024年小升初语文模拟考试试卷(含答案)
- 湖北省随州市随县2023-2024学年七年级下学期语文期末考试卷
- 2024年中国城建围挡板市场调查研究报告
- 北京市海淀区101中学2025届数学八年级第一学期期末统考试题含解析
- 重庆市渝中区巴蜀小学校2023-2024学年六年级下学期期末小升初数学试卷
- 专科医院医院财务预算管理知识考核试卷
- 2022-2023学年北京市西城区三帆中学七年级(上)期中数学试卷【含解析】
- 2024年中考语文真题分类汇编标点符号
- 渣土倾倒协议
评论
0/150
提交评论