2_processpcb.cpp
来自「实现PCB的模似程序,已经通过C++编译」· C++ 代码 · 共 73 行
CPP
73 行
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#define NULL 0
typedef struct processpcb
{ int id;/*进程控制块编号*/
struct processpcb *next;
}node;
int n;
node *creat(void) /*建立进程控制块队列表*/
{ node *head,*p1,*p2;
n=0;
printf("Input processpcb table:ID\n");
p1=p2=(node *)malloc(sizeof(node));
scanf("%d",&p1->id);
head=NULL;
while (p1->id>0)
{n=n+1;
if (n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(node *) malloc (sizeof(node));
scanf("%d",&p1->id);
}
p2->next=NULL;
return(head);
}
node *queue(node *head,int pcbin,int pcbout)
{node *p,*q;
p=head;q->id=pcbin;q->next=NULL;
if(!head)
head=q;
else
{while(p->next)
p=p->next;
p->next=q;
p=q;
}
p=head;
if(!head)
printf("not found!");
else
{while(p&&p->id!=pcbout)
{q=p;p=p->next;}
if(p)
{q->next=p->next;printf("found!");}
else
printf("not found!");
}
return(head);
}
void print (node *head) /*输出链表*/
{ node *p;
p=head;
if(head !=NULL)
do{printf("%d\t",p->id); p=p->next;}
while(p!=NULL);
}
void main()
{node *p,*q;
int pcbin,pcbout;
p=creat();
printf("\ninit_processpcb queue is:\n");
print(p);
printf("\nappend a processpcb\n");
scanf("%d",&pcbin);
printf("\ndel a processpcb\n");
scanf("%d",&pcbout);
p=queue(p,pcbin,pcbout);
printf("\n new processpcb queue is:\n");
print(p);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?