📄 jcdd2.c
字号:
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct pcb)
struct pcb
{ int pid;
struct pcb *next;
int time;
int priority;
char status;
};
int n,m;
struct pcb *head,*runpcb;
main()
{ struct pcb *pcbi;
char str;
struct pcb *cshlist();
void insertproc(struct pcb *insproc);
void pintlist(struct pcb *L);
void execproc();
void delproc();
m=0;
head=cshlist();
printf("first linelist is:\n");
pintlist(head);
while(head!=NULL)
{ scanf("%c",&str);
runpcb=head;
head=runpcb->next;
runpcb->status='Z';
printf("output linelist is:\n");
printf("%d\n",m);
printf("%2d %5d %5d %3c\n",runpcb->pid,runpcb->time,runpcb->priority,runpcb->status);
pintlist(head);
printf("\n");
printf("\n");
execproc();
m=m+1;
if(runpcb->time==0)
delproc();
else insertproc(runpcb);
}
}
void pintlist(struct pcb *L)
{
struct pcb *p;
int i;
p=L;
if(L!=NULL)
do
{ printf("%2d %5d %5d %3c\n",p->pid,p->time,p->priority,p->status);
p=p->next;
}while (p!=NULL);
}
struct pcb *cshlist()
{
struct pcb *ql;
n=0;
ql=(struct pcb *)malloc(LEN);
ql->pid=n+1;
ql->status='R';
printf("enter time and priority:\n");
scanf("%ld,%d",&ql->time,&ql->priority);
head=NULL;
while(ql->time!=0)
{
n=n+1;
insertproc(ql);
ql=(struct pcb *)malloc(LEN);
printf("enter time and priority:\n");
ql->pid=n+1;
ql->status='R';
}
return(head);
}
void insertproc(struct pcb *insproc)
{
struct pcb *p0,*p1,*p2;
int pri;
p1=head;
p0=insproc;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
pri=p0->priority;
if(p1->priority<=pri)
{
p0->next=head;
head=insproc;
}
else
{
while((p1->next!=NULL)&&(p1->priority>pri))
{ p2=p1;
p1=p1->next;
}
if((p1->next!=NULL)||(p1->priority<=pri))
{
p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
}
}
void execproc()
{
runpcb->time=runpcb->time-1;
runpcb->priority=runpcb->priority-1;
}
void delproc()
{
struct pcb *p;
p=runpcb;
p->status='E';
printf("process P");
printf("%d",p->pid);
printf(" is finish\n");
printf("\n");
free(runpcb);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -