您好,欢迎光临本网站![请登录][注册会员]  
文件名称: fcfs实现算法饿不会
  所属分类: 网络攻防
  开发工具:
  文件大小: 3kb
  下载次数: 1
  上传时间: 2009-11-19
  提 供 者: lanse******
 详细说明: 就是C语言#include #include #define MAX 5 //进程数 /*短作业优先算法*/ struct pro { int num; //进程名 int arriveTime; //到达时间 int burst; //运行时间; struct pro *next; }; //函数声明 struct pro* creatList(); void insert(struct pro *head,struct pro *s); struct pro* searchByAT(struct pro *head,int AT); void run(struct pro *head); void del(struct pro* p); int getCount(struct pro *head,int time); struct pro* creatList() //创建链表,按照进程的到达时间排列 { struct pro* head=(struct pro*)malloc(sizeof(struct pro)); head->next=NULL; struct pro* s; int i; for(i=0;inum)); printf("请输入到达时间:\n"); scanf("%d",&(s->arriveTime)); printf("请输入运行时间:\n"); scanf("%d",&(s->burst)); s->next=NULL; insert(head,s); } return head; } void insert(struct pro *head,struct pro *s) //插入节点 { struct pro *p=searchByAT(head,s->arriveTime); s->next=p->next; p->next=s; return; } struct pro* searchByAT(struct pro *head,int AT) //查找第一个到达时间大于等于AT的节点,返回其前一个指针 { struct pro *p,*q; p=head; q=head->next; while(q!=NULL&&q->arriveTime<=AT) { p=q; q=q->next; } return p; } void del(struct pro* p) //删除p的下一个节点 { struct pro *tmp; tmp=p->next; p->next=tmp->next; free(tmp); return; } int getCount(struct pro *head,int time) //察看当前就绪队列中的进程数 { int count=0; struct pro *p,*q; p=head; q=p->next; while(q!=NULL&&q->arriveTime<=time) { count++; p=q; q=q->next; } return count; } struct pro* SJF(struct pro *head,int count) //在头节点后的count个节点中选择burst最小的,返回其前一个节点的指针 { int min; struct pro *p,*q,*flag; p=head; q=p->next; min=q->burst; flag=p; //flag记录返回指针 while(count>0) { if(q->burstburst; flag=p; } count--; p=q; q=q->next; } return flag; } void run(struct pro *head) //按短作业优先算法调度进程,并输出其运行情况 { int time=0,count; struct pro *s,*t; while(head->next!=NULL) { count=getCount(head,time); if(count==0) //如果当前就绪队列中没有进程,时间自增 time++; else if(count==1) //如果就绪队列中只有1个进程,则必定是第一个节点 { t=head; s=t->next; printf("进程名:%d\n",s->num); printf("到达时间:%d\n",s->arriveTime); printf("运行开始时间:%d\n",time); printf("响应时间:%d\n",time-s->arriveTime); time+=s->burst; printf("运行结束时间:%d\n",time); printf("周转时间:%d\n",time-s->arriveTime); printf("*********************************\n"); del(t); } else //如果就绪队列中的进程数>=2,则在head后的count个节点中进行短作业优先调度 { t=SJF(head,count); s=t->next; printf("进程名:%d\n",s->num); printf("到达时间:%d\n",s->arriveTime); printf("运行开始时间:%d\n",time); printf("响应时间:%d\n",time-s->arriveTime); time+=s->burst; printf("运行结束时间:%d\n",time); printf("周转时间:%d\n",time-s->arriveTime); printf("*********************************\n"); del(t); } } } void main() { struct pro *head=creatList(); printf("按短作业优先算法调度运行结果如下:\n"); run(head); } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: C语言
 输入关键字,在本站1000多万海量源码库中尽情搜索: