#include
#include
#include
typedef struct PCB { /*定义一个结构体数组,包括进程的信息*/
char name[20] ;
float servertime;
float priority;
int flags;
struct PCB *next ;
}PCB,Linklist;
struct PCB *list;
insert(int s )
{ struct PCB *q,*b,*a;
q=(struct PCB*)malloc(sizeof(PCB));
puts("/ninput process name,servetime,priority/n");
scanf("%s%f%f",q->name,&q->servertime,&q->priority);
q->flags=0;
if(list->next==NULL)
{ q->next=list->next;
list->next=q;
}
else
{
if (q->priority>list->next->priority)
{
q->next=list->next;
list->next=q;
}
else
{ b=list->next;
a=b->next;
while(a->next!=NULL)
{
if(q->priority>a->priority&&q->prioritypriority)
{
q->next=a;
b->next=q;
}
else
{
b=a;
a=a->next;
}
}
q->next=a;
b->next=q;
}
}
}
Create(int n) /*初始化*/
{ int i;
for(i=n;i>0;--i)
{
insert(i);
}
running()
{
struct PCB *q,*b,*a;
q=list->next;
q->servertime-=1;
q->priority-=1;
if(q->servertime==0)
{
q->flags=1;
printf("/nto the end/n");
free(q);
}
else
{
if(list->next==NULL)
{
q->next=list->next;
list->next=q;
}
else
{
if ((q->priority)>(list->next->priority))
{
q->next=list->next;
list->next=q;
}
else
{
b=list->next;
a=b->next;
while(a->next!=NULL)
{
if((q->priority>a->priority)&&(q->prioritypriority))
{
q->next=a;
b->next=q;
}
else
{
b=a;
a=a->next;
}
}
q->next=a;
b->next=q;
}
}
}
}
void main()
{ int m ;
struct PCB *list;
list=(struct PCB*)malloc(sizeof(PCB));
list->next=NULL;
puts("/n input creat process number: ");
scanf("%d",&m);
Create(m);
running();
}