#define N 10
#define NULL 0
#define LEN sizeof(struct stru_pcb)
#include<iostream.h>
struct stru_pcb           //进程的结构体
{
        long  pid; //编号
        int status; //状态
        int priority;// 优先级
        char resource_list[20];//资源清单
        char createdatetime[10];//创建时间
        char note[100];//其他信息
        struct stru_pcb *next;    
};

typedef struct
{
        struct stru_pcb *front,*rear;    //队列的头指针和尾指针
}LQueue;

int create(LQueue *q)//创建进程队列
{
        if((q->front=(Node *)malloc(LEN))==NULL)
            return 0;
        q->rear=q->front;
        q->front->next=NULL;
        return 1;
}

int insert(LQueue *q,long pcb_pid,int pcb_status,int pcb_priority,char *pcb_resource_list,char *pcb_note)             //插入进程
{
        struct stru_pcb *pcb;
        if((pcb=(struct stru_pcb *)malloc(LEN))==NULL)
            return 0;
        pcb->pid=pcb_pid;
        pcb->status=pcb_status;
        pcb->priority=pcb_priority;
        while((pcb->resource_list=pcb_resource_list)!='\0')
           { pcb_resource_list++; pcb->resource_list++; }  
        while(pcb->note=pcb_note)
           { pcb_note++; pcb->note++; }
        pcb->next=NULL;
        q->rear->next=pcb;
        q->rear=pcb;
        return 1;                        
}


int print(LQueue *q)  //输出进程队列
{
        struct stru_pcb *p    ;
          if(!(q->front==q->rear))
                  {
                          printf("队空");
                          return 0;
                  }
            while(1){
                    p=q->front->next;
                    q->front->next=p->next;
                    printf("进程编号:%p->pid,进程的状态:%p->status,进程的优先级:%p->priority,
                            进程的资源清单:%p->resource_list,其他:%p->note\n",
                            p->pid,p->status,p->priority,p->resource_list,p->note);                                                    
                    free(p);
                    if(q->fornt->next==NULL)
                        {
                                q->rear=q->front;
                                return 1;
                        }                                                            
            }                    
}


void main()
{
    LQueue *q;
    int i,j;
    struct stru_pcb[N];
    
    create(q);
    for(i=0;i<N;i++)
    {   
        j=i+1;
        printf("请输入进程(pid=%d)的信息:\n");
        pcb[i]=j;        
        printf("进程状态:1=就绪,2=运行,3=阻塞\n");
        scanf("%d",&pcb[i].status;
        printf("进程的优先级(-127~127)\n");
        scanf("%d",&pcb[i].priority);
        printf("进程的资源清单\n");
        scanf("%d",&pcb[i].resource_list);
        printf("其他\n");
        scanf("%d",&pcb[i].note);

                
        insert(q,pcb[i],pcb[i].status,pcb[i].priority,
        pcb[i].resource_list,pcb[i].note);

        print(q);
    }
}