已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年河北女子职业技术学院单招职业适应性测试题库及答案详解一套
- 2026年湖北城市建设职业技术学院单招职业倾向性测试题库附答案
- 2026年梧州职业学院单招职业倾向性考试题库及完整答案详解1套
- 2026年西南交通大学希望学院单招职业技能测试题库及参考答案详解一套
- 2026中信证券福建分公司校园招聘(公共基础知识)测试题带答案解析
- 2026年福建水利电力职业技术学院单招职业技能考试题库附答案
- 2026年重庆市乐山市单招职业适应性考试题库附答案
- 2026年漯河食品职业学院单招职业适应性考试模拟测试卷附答案
- 2026年铜仁职业技术学院单招职业适应性考试模拟测试卷附答案
- 2026年浙江宇翔职业技术学院单招职业倾向性考试题库及参考答案详解一套
- 中国心力衰竭诊断和治疗指南2024解读
- TDT 1070.4-2022 矿山生态修复技术规范 第4部分:建材矿山
- 自愿放弃入伍承诺书
- 0031预防成人经口气管插管非计划性拔管护理专家共识
- 英才学院《电工学》习题库及答案05继电接触控制系统
- 原发性支气管肺癌教案
- 废弃物管理及处理程序
- 2023年西安市政道桥建设集团有限公司招聘笔试题库及答案解析
- GB/T 28734-2012固体生物质燃料中碳氢测定方法
- 智慧树创意学经济测试题答案
- 《我的心儿怦怦跳》优秀课件
评论
0/150
提交评论