我自己做了一个,就是不能运行,请求帮我看看
谢谢了!
#include<stdio.h>
#include<stdlib.h>
typedef enum{ready,block}two;
typedef struct pcb{int id;
int priority;
int cputime;
int blocktime;
two state;
struct pcb*next;}pcbnode;
typedef struct queue{pcbnode*front;
pcbnode*rear;
}queuetype;
queue ready,block;
int empty(queuetype*q)
{return(q->front==q->rear);}
void enqueue(queuetype*q,pcbnode*x)
{if(empty(q))
q->front=q->rear=x;
else{q->rear->next=x;
q->rear=x;}
}
void creatprocess(int t)
{ int i,a=60,b=1,c=30,d=1,n;
n=t;
for(i=0:i<n;i++)
{p=(pcbnode*)malloc(sizeof(pcbnode));
p.id=i;
p.cputime=b++;
p.next=null;
if(i<2n/3)
{p.priority=a--;
p.two=ready;
p.blocktime=0;
}
else {p.priority=c--;
p.two=block;
p.blocktime=d++;}
if(p.two==ready) enqueue(&ready,p);
else enqueue(&block,p);
}
pcbnode getmaxpriority(queuetype*q)
{pcbnode*p;
if(empty()) return null;
else{p=q->front->next;
return(p);}
void insertreadyqueue(ready*q,pcbnode*X)
{ pcbnode*r,s;
s=q->front;
if(empty()) q->front=q->rear=x;
else {
while((q->front->priority>x.priority)&&s)
{r=s;
s=s->next;}
if(S)
{r->next=x;
x->next=s;}
else
{s->next=x;
x->next=null;}
}
}
void delete(block*q,pcbnode*x)
{pcbnode*p;
p=q->front;
if(p&&p==x)
{p->next=p->next->next;
free(p);
}
else p=p->next;
}
void subblocktime(block*q)
{pcbnode*p;
p=q->front;
while(p)
{p.blocktime--;
if(p.blocktime==0) { delete(&block,p);
insert(&ready,p);
}
p=p->next;}
}
void print(queuetype*q)
{pcbnode*p;
p=q->front;
while(p)
{printf("%d%d%s\n",p.id,p.priority,p.state);
p=p->next;}
}
void control()
{int t=10,i=0;
pcbnode*p;
p=getmaxpriority();
while(t==0&&p)
{for(i=0;i<10;i++)
t--;
if(t==0){
p.priority-=3;
p.cputime--;
if(p.cputime==0) free(p);
else insert(&ready,p);
subblocktime();}
t=10;}
}
main()
{creatprocess(90);
control():
print(&ready);
print(&block);
}