已阅读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内蒙古煤炭地质勘查(集团)一一七有限公司招聘9人笔试历年备考题库附带答案详解
- 2025内蒙古包头供销投资(集团)有限责任公司招聘2人笔试历年常考点试题专练附带答案详解
- 古老建筑维修技艺考核表
- 2025云南保山电力股份有限公司招聘(100人)笔试历年备考题库附带答案详解2套试卷
- 2025中检浙北检验认证(浙江)有限公司招聘6人笔试历年备考题库附带答案详解
- 2025中国平煤神马控股集团招聘825人(本科及以上)笔试历年常考点试题专练附带答案详解
- 2025中健鑫诚(河南)企业管理有限公司招聘21人笔试历年常考点试题专练附带答案详解
- 电商卖家店铺运营数据化分析方案
- 小学主题班会课件:宽容待人与公平竞争
- 酒店高级前厅部主管KPI考核表
- 光伏图纸基础知识培训课件
- JJG 264-2025 谷物容重器检定规程
- 爆米花教学课件
- 高职学校教师培训体系构建
- 先天性甲状腺功能减退症诊治指南(2025)解读
- DB63T 1788-2020小叶香菜制种技术规程
- 网点功能布局及客户动线管理
- 医院检验科院感课件
- 兄弟自动切线平缝机S-7000DD中文使用说明书
- 海事集装箱装箱检查员考试题库
- 2024年挂车配件项目可行性研究报告
评论
0/150
提交评论