#include <stdio.h>
#include <stdlib.h>
int MAX;
/*短作业优先算法*/
struct pro
{
int num; //进程名
int arriveTime; //到达时间
int service; //服务时间;
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;i<MAX;i++)
{
s=(struct pro*)malloc(sizeof(struct pro));
printf("请输入进程名:\n");
scanf("%d",&(s->num));
printf("请输入到达时间:\n");
scanf("%d",&(s->arriveTime));
printf("请输入服务时间:\n");
scanf("%d",&(s->service));
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;
- 1
- 2
- 3
前往页