#include <malloc.h>
#include <stdio.h>
#include <string.h>
typedef struct processpcb
{
int id; /*进程控制块编号*/
struct processpcb *next;
}node;
node *creat(void) //创建进程控制块
{
node *head, *p1, *p2;
int 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;
free (p1);
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);
}
node *append(node *head, node *q)
{
node *p;
p = head;
if (!head)
head = q;
else {
while (p->next)
p = p->next;
p->next = q;
}
return head;
}
int main(void)
{
node *p, *q;
int pcbid;
p = creat(); //创建进程控制块表
printf("\nappend a processpcb\n");
scanf("%d",&pcbid);
q=(node *)malloc(sizeof(node));
q->id=pcbid;
q->next=NULL;
printf("\ninit_processpcb queue is:\n"); //输出原有的队列
print(p);
p=append(p,q);
printf("\nappend_processpcb queue is:\n");
print(p);
return 0;
}
进程入队
最新推荐文章于 2020-02-01 00:43:03 发布