⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2_prior.cpp

📁 实例91 文字跑马灯与信息窗口
💻 CPP
字号:
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#define NULL 0
typedef struct table
 { int key;             /*进程ID号*/
   int priority;        /*优先数值*/
   char message[10];    /*进程说明信息*/
   struct table *next;
 }node;
 node *creat(void) /*定义函数,建立进程链表*/
 { node *head;
   node *p1,*p2;
   int n=0;
   p1=p2=(node *)malloc(sizeof (node));
   scanf("%d %d",&p1->key,&p1->priority);
   gets(p1->message);
   head=NULL;
   while (p1->key!=0)/*输入0表示结束*/
     {
     n=n+1;
     if (n==1) head=p1;
     else p2->next=p1;
     p2=p1;
     p1=(node *) malloc(sizeof (node));
     scanf("%d %d",&p1->key,&p1->priority);
     gets(p1->message);
   }
   p2->next=NULL;
   return(head);
 }

 void print (node *head)  /*输出链表*/
 { node *p;
   printf("\n The table is:\n");
   p=head;
   while(p)
     { 
      printf("%d,%d,%s\n",p->key,p->priority,p->message);
      p=p->next;
     }
  }
node *processdo(node *head)/*模拟当前最大优先数进程出队的过程*/
 { int prior;
   static int count=0;
   node *p,*pre;
   p=pre=head;
   prior=p->priority;count++;
   while(p)                  /*找出优先数最大进程*/
    {if(p->priority>prior)
        prior=p->priority;
     p=p->next;
    }
   p=head;
   while(p->priority!=prior)
    { pre=p;p=p->next;}
   printf("\n第%d次出队的进程为:\n",count);
   printf("key=%d,priority=%d,message=%s\n",p->key,p->priority,p->message);
   if(p==head)
     head=head->next;
   else
     pre->next=p->next;
  return(head);
 }
 void main()
 {
   node *p,*q;
   printf("新建的进程控制表为:\nkey priority message\n");
   p=q=creat(); /*输入进程控制表*/
   print(p);/*输出原始进程控制表*/
   while(p)/*模拟逐个出队并进入CPU运行的过程*/
    { q=processdo(p);
      p=q;
    }
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -