




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Pcb.h:#ifndef PCH_H#define PCB_Hstruct pcbint num;char name10;int in_time;int server_time;int finish_time;int cur_time;float power_cur_time;#endifList.h:#ifndef LIST_H_#define LIST_H_#includepcb.htypedef struct liststruct pcb _pcb;struct list *next;List,*pList;void InitList(List *pHead);void InsertHead( List *pHead,int _num,char *_name,int _in_time,int _server_time);void Delete(List *phead,List *p);void Insert(List *phead,List *p);List * FindMin(List *phead);List * FindShort(List *phead);void InsertArriver(List *phead,List *desHead,int time);static List *BuyNode();void Print(List *phead);#endifList.c:#include#include#includelist.h#include#include#includeusing namespace std;void InitList(List *pHead)*pHead=BuyNode();(*pHead)-next = NULL;void InsertHead(List *pHead,int _num,char *_name,int _in_time,int _server_time)List *p=BuyNode();assert( *pHead != NULL );assert(p!=NULL);(p-_pcb).num=_num;strcpy(p-_pcb).name,_name);(p-_pcb).in_time=_in_time;(p-_pcb).server_time=_server_time;p-next=(*pHead)-next;(*pHead)-next=p;void Delete(List *phead,List *p)List *pre=phead;while(pre-next != p)pre=pre-next ;pre-next=pre-next -next ;void Insert(List *phead,List *p)List *pre=phead;/List *pInsert=while(pre-next!= NULL&pre-next != p )pre=pre-next ;p-next =pre-next ;pre-next =p;static List *BuyNode()List *p=(List *)malloc(sizeof(List);assert(p!=NULL);return p;List * FindMin(List *phead)assert(phead != NULL & phead-next != NULL);int min_intime=phead-next -_pcb.in_time;List *p=phead-next;List *pdes=p;while(p!=NULL)if(p-_pcb.in_time _pcb.in_time;pdes=p;p=p-next ;return pdes;List * FindShort(List *phead)assert(phead != NULL & phead-next != NULL);int min_intime=phead-next -_pcb.server_time;List *p=phead-next;List *pdes=p; while(p!=NULL)if(p-_pcb.server_time _pcb.server_time;pdes=p;p=p-next ;return pdes; void InsertArriver(List *phead,List *desHead,int time)assert(phead != NULL & phead-next !=NULL);List *pcur=phead-next ;List *p=pcur;while(pcur!=NULL )if(pcur-_pcb.in_time next;Delete(phead,p);Insert(desHead,p);elsepcur=pcur-next;void Print(List *phead)if(phead!=NULL & phead-next != NULL)List *pcur=phead-next;while(pcur!=NULL)coutnum _pcb.numendl;coutname _;coutintime _pcb.in_timeendl;coutservertime _pcb.server_timeendl;coutfinish _pcb.finish_timeendl;coutcurtime _pcb.cur_timeendl;coutpower_cur_time _pcb.power_cur_timeendl;coutnext ;Spf.h:#ifndef _SPF_#define _SPF_void spf(List *phead,List *pheadAccom);#endifSpf.cpp:#includelist.h#include#includespf.hvoid spf(List *phead,List *pheadAccom)List *ArriveHead=NULL;InitList(&ArriveHead);int finish_time=0;int lastAccom_time=0;List *p=NULL;while(phead-next != NULL | ArriveHead-next !=NULL)if(phead-next != NULL) InsertArriver(phead,ArriveHead,finish_time);p=FindShort(ArriveHead);finish_time=lastAccom_time+p-_pcb .server_time ;p-_pcb .finish_time=finish_time;lastAccom_time=finish_time;p-_pcb .cur_time=p-_pcb.finish_time -p-_pcb .in_time ;p-_pcb.power_cur_time=float(p-_pcb.cur_time )/float( p-_pcb.server_time);Delete(ArriveHead,p);Insert(pheadAccom,p);Fcfs.h:#ifndef FCFS_#define FCFS_void Fcfs(List *phead,List *pheadAccom);#endifFcfs.cpp:#include#includelist.h#includeFcfs.hvoid Fcfs(List *phead,List *pheadAccom)List *p=NULL;int min_intime=0;int finish_time=0;int lastAccom_time=0;while(phead-next != NULL)p=FindMin(phead);finish_time=lastAccom_time+p-_pcb .server_time ;p-_pcb .finish_time=finish_time;lastAccom_time=finish_time;p-_pcb .cur_time=p-_pcb.finish_time -p-_pcb .in_time ;p-_pcb .power_cur_time =float(p-_pcb.cur_time )/float( p-_pcb.server_time);Insert(pheadAccom,p);Delete(phead,p);Main.cpp:#include#include#include#includelist.h#includeFcfs.h#includeSPF.Husing namespace std;int main()char name10=0;int in_time=0;int server_time=0;int i=1;char x=0;List *head=NULL;List *SPFAccom=NULL;List *FCFSAccom=NULL;InitList(&head);InitList(&SPFAccom);InitList(&FCFSAccom);printf(请输入进程的信息n);printf(进程名 到达时间 服务时间n);while(true)printf(请输入第%d个进程信息n,i);fgets(name,10,stdin);scanf(%d,&in_time);scanf(%d,&server_time);InsertHead(&head,i,name,in_time,serve
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 商业智慧教育美妆品牌的市场策略与方向
- 医疗科技的创新之路基于设计思维的实践与探索
- 全球教育趋势与国际化发展战略规划
- 从学生心理角度看教育改革与发展趋势
- 商业培训中的互动游戏化教学策略研究
- 抖音商户直播样品签收确认制度
- 抖音商户直播停留时长优化方案执行制度
- 公交优先战略下2025年城市交通拥堵治理的智能交通设施布局分析报告
- CDK9-IN-38-生命科学试剂-MCE
- 浙江省温州市各学校2025届化学九年级第一学期期末检测试题含解析
- 订婚解除婚约协议书模板
- 进入车间管理制度
- 急性肝衰竭的护理查房
- 卵巢癌教学查房课件
- 全国职业大赛(中职)ZZ006水利工程制图与应用赛项赛题第2套
- 监控安装项目计划书
- 《公共危机管理概论》复习题
- 运维保障方案表
- 急性肺栓塞抢救流程
- 2024初高中物理衔接 课件
- 四年级上册数学每天20道口算、4道竖式、4道脱式、2道应用题寒假作业剖析
评论
0/150
提交评论