实验一: 进程状态转换及PCB的模拟
10
丁蕾蕾
开始于 2018-04-01 18:38
94 40 262
已截止

任务尚未发布或者你没有权限查看任务内容。

任务讨论

@蕾蕾老师‍  补交作业,之前忘记提交了

#include <iostream> 
#include <stdlib.h>        
#include <time.h>
using namespace std;

//优先级:p_priority大的优先级高
struct PCB{
    int p_priority; //优先数
    //int p_atime; //到达时间
    int p_rtime; //需要运行时间
    int p_cpu; //已占CPU时间
    char p_name; //进程名
    char p_state; //进程状态:Wait、Run、Finish
    PCB *next; //指向下一个PCB
};

struct Link{
    PCB*front;  //队头指针
    PCB* rear;   //队尾指针
};

bool InitQueue(Link * P) //构造一个空就绪队列
{
    P->front=P->rear =new PCB;
    P->front->next=NULL;
    return true;
}

void EnQueue(Link * P,PCB*e_pcb)//插入元素
{
    if(P->front->next==NULL)
    {
        P->front->next=e_pcb;
        e_pcb->next=NULL;
    }
    else
    {
        PCB*p=P->front->next;
        while(p->next!=NULL){
            p=p->next;
        }
        p->next=e_pcb;
        e_pcb->next=NULL;
    }
}

void DeQueue(Link * P,PCB*e_pcb) //将进程从就绪队列中删除
{
    if(e_pcb->next==NULL)
    {
         P->front->next=NULL;
    }
    else
    {
        P->front->next=e_pcb->next;
    }
}

char RunState(PCB*e_pcb){//进程状态改变
    if(e_pcb->p_cpu==0)
        e_pcb->p_state='W';
    else if(e_pcb->p_cpu<e_pcb->p_rtime)
        e_pcb->p_state='R';
    else
        e_pcb->p_state='F';
    return e_pcb->p_state;
}

int main(void){

    PCB*p1=new PCB;
    p1->p_priority = 4;
    p1->p_rtime=3;    
    p1->p_name='f';
    p1->p_state='W';
    p1->p_cpu=0;

    PCB*p2=new PCB;
    p2->p_priority=2;
    p2->p_rtime=2;
    p2->p_name='s';
    p2->p_state='W';
    p2->p_cpu=0;

    Link R;
    InitQueue(&R);
    EnQueue(&R,p1);
    EnQueue(&R,p2);

      PCB*tempt=R.front->next;
      do{
        cout<<"进程名称"<<tempt->p_name<<endl;  //名称
        cout<<"优先数"<<tempt->p_priority<<endl;    //优先数
        cout<<"运行时间"<<tempt->p_rtime<<endl;   //运行时间
        cout<<"运行状态"<<tempt->p_state<<endl;   //运行状态
        cout<<"已运行时间"<<tempt->p_cpu<<endl; //已运行时间
        tempt->p_cpu++;   
        tempt->p_priority--;
        RunState(tempt);
        cout<<"时间片运行过后: "
            << "优先数: "<< tempt->p_priority
            <<"; 已运行时间:  "<< tempt->p_cpu
            <<"; 运行状态: "<<tempt->p_state <<endl;
        if(tempt->p_cpu < tempt->p_rtime){
            DeQueue(&R,tempt);
            EnQueue(&R,tempt);
        }
        else{
            DeQueue(&R,tempt);
        }
            tempt=R.front->next;
    }while(1);

    return 0;
}

/*
康祁鑫
软件八班
2016011700
*/ #include<iostream> using namespace std; #define NULL 0 struct pcb{/*定义进程控制块PCB */   char name[10];  //进程名   char state;   //进程状态   int super;   //优先数   int ntime;   //请求服务时间   int rtime;   //已运行时间   struct pcb* next;  }*Ready=NULL,*p;  typedef struct pcb PCB;  void sort()  {  
	 PCB *first,*second;   int insert=0; 
  if((Ready==NULL)||((p->super)>(Ready->super)))   {   
		p->next=Ready;    Ready=p; 
  }   else      { 
  		first=Ready;   
		second=first->next;    while(second!=NULL)    {     if((p->super)>(second->super))     {     
				p->next=second;     
				first->next=p;     
				second=NULL;     
				insert=1; 
    }     else   
  { 
				first=first->next;     
				second=second->next;  } 
         } 
   if (insert==0) first->next=p; 
  }  }  void input() { 
   int i,num; 
   cout<<"请输入进程总数:";    
   cin>>num;    
   cout<<endl;     for(i=1;i<=num;i++)     { 
      cout<<"进程号No.:"<<i<<endl;    
	  p=(PCB*)malloc (sizeof(PCB)); 
   	  cout<<"输入进程名、优先数、需要运行时间:";    
	  cin>>p->name>>p->super>>p->ntime;    
	  cout<<endl;    
	  p->rtime=0;    
	  p->state='W';       
	  p->next=NULL;    
	  sort();   
   }  } void disp(PCB *pr)  { 
  cout<<"进程名:    "<<"状态:    "<<"优先级:    "<<"请求服务时间:    "<<"已运行时间:    "<<endl; 
  cout<<"  "<<pr->name<<"           "<<pr->state<<"        "<<pr->super<<"            "<<pr->ntime<<"              "<<pr->rtime<<endl;  }  void check() { 
  PCB *pr; cout<<endl<<"****当前正在运行的进程是:"<<p->name<<endl;    (p->rtime)++;   
  disp(p);   
  pr=Ready;    if(pr!=NULL)   { 
  cout<<endl<<"****当前就绪队列中的进程为:"<<endl;    while(pr!=NULL)    { 
     disp(pr);  
 	 pr=pr->next;     }    }  }  void running()    {    
   if(p->rtime==p->ntime)    //运行完后回收PCB     {     
	   cout<<endl<<"进程"<<p->name<<"已完成"<<endl;  
   	   free(p);  
   }     else     { 
      (p->super)--;    //运行完一时间片后,未完成,则降低优先级      p->state='W';     
	  sort();    //重新排序     }  }  void main() { 
    int h=0;   char ch;  
	input();      while(Ready!=NULL) 
 { 
    ch=getchar();  
    h++; cout<<"正在执行的时间片为:"<<h<<endl;     
	p=Ready;         Ready=p->next;        
	p->next=NULL; 
    p->state='R';     
	check(); 
	running();      
    cout<<"按回车键继续......"<<endl;        } 
    cout<<endl<<"进程已全部执行完毕!"<<endl;  }
#include<stdio.h> #include<stdlib.h> typedef struct pcb{ char name;//进程名称 int arrivetime;//进程到达时间 int count;//优先数 int dotime;//进程运行时间 int cputime;//占用cpu时间 char state;//进程状态 struct pcb *next; }pcb; pcb*head=(pcb*)malloc(sizeof(pcb)); pcb*head1=(pcb*)malloc(sizeof(pcb)); void sort() { pcb*t=head; pcb *q,*p,*r; int max; while(t->next!=NULL) { q=head; p=t->next; r=t->next; max=r->count; while(r!=NULL) { if(r->count>max){ max=r->count; p=r; } r=r->next; } q=t; while (q->next != p) q = q->next; if(t->next != p) { q->next = p->next; p->next = t->next; t->next = p; }// 插入进行排序按照优先数  t=t->next; } } bool create(){//创建进程函数 pcb*q=head; pcb*p=head1; printf("请输入进程的数量:"); int n; scanf("%d",&n);//进程的数量 for(int i=0;i<n;i++){ pcb* temp=(pcb*)malloc(sizeof(pcb)); if(temp) return false; printf("进程名称:"); scanf("%s",&(temp->name)); printf("进程到达时间:"); scanf("%d",&(temp->arrivetime)); printf("优先数:"); scanf("%d",&(temp->count)); printf("进程运行时间:"); scanf("%d",&(temp->dotime)); printf("占用cpu时间:"); scanf("%d",&(temp->cputime)); printf("进程状态:"); scanf("%s",&(temp->state)); if(temp->arrivetime=0) { q->next=temp; q=temp; } else{ p->next=temp; p=temp; } } sort(); return true; } void arrivefunction() { pcb*q=head1->next; pcb*t; while(q->next!=NULL) { q->arrivetime--; if(q->arrivetime==0) { t=head1; while(t->next!=q) { t=t->next; } t->next=q->next; q->next=head->next; head->next=q; } q=q->next; } } void display(pcb*pro) { printf("进程名称:%s",pro->name); printf("进程优先数:%d",pro->count); printf("进程所占时间片:%d",pro->dotime); printf("进程已运行时间:%d",pro->cputime); printf("进程当前状态:%s",pro->state); } void destory(pcb*pro) { pcb *q = pro->next; head->next = q; free(pro); } void cpufunction(pcb*pro) { pro->cputime++; arrivefunction(); printf("正在运行的进程"); display(pro); if(pro->cputime==pro->dotime) { destory(pro); } else { pro->count--; pro->state = 'W'; } pcb *p = head; if(head->next==NULL&&head1->next==NULL) return; while(p->next!=NULL) { display(p->next); p = p->next; } pcb *q = head1; while(q->next!=NULL) { display(q->next); q = q->next; } sort(); } int main(){ create(); pcb*pro; while(head->next!=NULL || head1->next!=NULL) // 判断两个对列的进程是否都走完  { if(head->next!=NULL) { pro= head->next; pro->state='R'; cpufunction(pro); } else { arrivefunction(); } } return 0; }
/*PCB的模拟
*班级:2016级1班
*学号:2016011358
*姓名:张旭磊
*/
#include <stdio.h>  
#include <malloc.h>
  
typedef struct pcb  
{  
	int name; // 进程的名称  
	char state;// 进程的状态  
	int arrivetime; //进程的到达时间  
	int runtime;// 进程的执行时间  
	int cputime;//cpu占用的时间  
	int count;//优先数  
	struct pcb *next;  
}pcb;  
pcb *head = NULL; // 正常对列  
pcb *head1 = NULL; // 未到达的对列  
int n = 0;// 进程的数量  
//创建头指针  
void createhead()  
{  
	// 创建头指针  
	pcb *p = (pcb*)malloc(sizeof(pcb));
	head = p;  
	// 创建头指针
	pcb *q = (pcb*)malloc(sizeof(pcb));  
	head1 = q;  
}  
// 按照优先数进行排序 
void sort() 
{  
	pcb* t = head;  
	pcb *q,*p,*r;  
	int max;  
	// 用t遍历正常队列
	while(t->next != NULL)  
	{  
		p = t->next;  
		r = t->next;  
		max = r->count;  
		// p指向count最大的那一个节点
		while(r!= NULL)  
		{  
			if(r->count > max)  
			{  
				max = r->count;  
				p = r;  
			}  
			r = r->next;  
		}
		//使q的节点的next指向优先级最高节点
		q = t;  
		while (q->next != p)  {
			q = q->next;  
		}
		// 插入进行排序按照优先数 
		if(t->next != p)  
		{  
			q->next = p->next;  
			p->next = t->next;  
			t->next = p;  
		} 
		t = t->next;  
	}  
}  
//创建pcb操作  
int create() 
{  
	int i=0;
	createhead();  
	pcb *p = head;  
	pcb *q = head1;  
	printf("请输入进程数目:");  
	scanf("%d",&n);  
	pcb *temp;  
	//建立就绪队列  
	for(i=1;i<=n;i++ )
	{  
		temp = (pcb*)malloc(sizeof(pcb));  
		if(!temp) return 0;  
		printf("请输入进程%d的要求运行时间,进程优先数,到达时间:",i);  
		scanf("%d %d %d",&(temp->runtime),&(temp->count),&(temp->arrivetime));  
		temp->cputime = 0;  
		temp->name=i;  
		temp->next = NULL;  
		temp->state='W';  
		// 对到达时间进行判断
		if(temp->arrivetime!=0)   
		{  
			q->next = temp;  
			q = temp;  
		}  
		else  
		{  
			p->next = temp;  
			p = temp;  
		}  
	}  
	sort();   
	return 1;  
}  
// 撤销操作 
void destory(pcb *rp) 
{  
	printf("\n进程%d已完成\n",rp->name);  
	pcb *q = rp->next;  
	head->next = q;  
	free(rp);  
}  
// 展示当前的信息 
void display(pcb *rp)  
{  
	printf("进程名字:%d",rp->name);  
	printf("\n进程优先级:%d",rp->count);  
	printf("\n进程所占时间片:%d",rp->runtime);  
	printf("\n进程已运行时间:%d",rp->cputime);  
	printf("\n进程当前状态:%c",rp->state);  

}  
// 对于到达时间-1的操作
void arrivetime()  
{  
	pcb *q = head1->next;  
	pcb *r,*t;  
	 // 判断到达时间是否为0 此时是否到达  
	while(q!=NULL)
	{  
		q->arrivetime--;  
		if(q->arrivetime==0)  
		{  
			t = head1;  
			while(t->next!=q)  
				t = t->next;  
			t->next = q->next;  
			r = head->next;  
			q->next = r;  
			head->next = q;  
		}  
		q = q->next;  
	}  
}  
void runpcb(pcb *rp)  
{  
	//修改cpu占用的时间 
	rp->cputime++;  
	arrivetime();  
	// 输出正在运行的队列 
	printf("正在运行的进程:\n");  
	display(rp);  
	if(rp->cputime==rp->runtime)  
	{  
		destory(rp);  
	}  
	else  
	{  
		rp->count--;  
		rp->state = 'W';  
	}  
	pcb *p = head;  
	if(head->next==NULL&&head1->next==NULL) return;  
	// 输出就绪的队列 
	printf("\n处于就绪对列的进程\n");  
	while(p->next!=NULL)  
	{  
		display(p->next);  
		p = p->next;  
	}  
	pcb *q = head1;  
	while(q->next!=NULL)  
	{  
		display(q->next);  
		q = q->next;  
	}  
	sort();  
}  
int main()  
{  
	// 创造进程
	create();  
	pcb * p;  
	// 判断两个对列的进程是否都走完 
	while(head->next!=NULL || head1->next!=NULL)  
	{  
		if(head->next!=NULL)  
		{  
			p= head->next;  
			p->state='R';  
			runpcb(p);  
		}  
		else  
		{  
			arrivetime();  
		}  
	}  
	system("pause");
	return 0;  
}  
#include <stdio.h>  
#include <malloc.h>
  
typedef struct pcb  
{  
	int name; // 进程的名称  
	char state;// 进程的状态  
	int arrivetime; //进程的到达时间  
	int runtime;// 进程的执行时间  
	int cputime;//cpu占用的时间  
	int count;//优先数  
	struct pcb *next;  
}pcb;  
pcb *head = NULL; // 正常对列  
pcb *head1 = NULL; // 未到达的对列  
int n = 0;// 进程的数量  
//创建头指针  
void createhead()  
{  
	// 创建头指针  
	pcb *p = (pcb*)malloc(sizeof(pcb));
	head = p;  
	// 创建头指针
	pcb *q = (pcb*)malloc(sizeof(pcb));  
	head1 = q;  
}  
// 按照优先数进行排序 
void sort() 
{  
	pcb* t = head;  
	pcb *q,*p,*r;  
	int max;  
	// 用t遍历正常队列
	while(t->next != NULL)  
	{  
		p = t->next;  
		r = t->next;  
		max = r->count;  
		// p指向count最大的那一个节点
		while(r!= NULL)  
		{  
			if(r->count > max)  
			{  
				max = r->count;  
				p = r;  
			}  
			r = r->next;  
		}
		//使q的节点的next指向优先级最高节点
		q = t;  
		while (q->next != p)  {
			q = q->next;  
		}
		// 插入进行排序按照优先数 
		if(t->next != p)  
		{  
			q->next = p->next;  
			p->next = t->next;  
			t->next = p;  
		} 
		t = t->next;  
	}  
}  
//创建pcb操作  
int create() 
{  
	int i=0;
	createhead();  
	pcb *p = head;  
	pcb *q = head1;  
	printf("请输入进程数目:");  
	scanf("%d",&n);  
	pcb *temp;  
	//建立就绪队列  
	for(i=1;i<=n;i++ )
	{  
		temp = (pcb*)malloc(sizeof(pcb));  
		if(!temp) return 0;  
		printf("请输入进程%d的要求运行时间,进程优先数,到达时间:",i);  
		scanf("%d %d %d",&(temp->runtime),&(temp->count),&(temp->arrivetime));  
		temp->cputime = 0;  
		temp->name=i;  
		temp->next = NULL;  
		temp->state='W';  
		// 对到达时间进行判断
		if(temp->arrivetime!=0)   
		{  
			q->next = temp;  
			q = temp;  
		}  
		else  
		{  
			p->next = temp;  
			p = temp;  
		}  
	}  
	sort();   
	return 1;  
}  
// 撤销操作 
void destory(pcb *rp) 
{  
	printf("\n进程%d已完成\n",rp->name);  
	pcb *q = rp->next;  
	head->next = q;  
	free(rp);  
}  
// 展示当前的信息 
void display(pcb *rp)  
{  
	printf("进程名字:%d",rp->name);  
	printf("\n进程优先级:%d",rp->count);  
	printf("\n进程所占时间片:%d",rp->runtime);  
	printf("\n进程已运行时间:%d",rp->cputime);  
	printf("\n进程当前状态:%c",rp->state);  

}  
// 对于到达时间-1的操作
void arrivetime()  
{  
	pcb *q = head1->next;  
	pcb *r,*t;  
	 // 判断到达时间是否为0 此时是否到达  
	while(q!=NULL)
	{  
		q->arrivetime--;  
		if(q->arrivetime==0)  
		{  
			t = head1;  
			while(t->next!=q)  
				t = t->next;  
			t->next = q->next;  
			r = head->next;  
			q->next = r;  
			head->next = q;  
		}  
		q = q->next;  
	}  
}  
void runpcb(pcb *rp)  
{  
	//修改cpu占用的时间 
	rp->cputime++;  
	arrivetime();  
	// 输出正在运行的队列 
	printf("正在运行的进程:\n");  
	display(rp);  
	if(rp->cputime==rp->runtime)  
	{  
		destory(rp);  
	}  
	else  
	{  
		rp->count--;  
		rp->state = 'W';  
	}  
	pcb *p = head;  
	if(head->next==NULL&&head1->next==NULL) return;  
	// 输出就绪的队列 
	printf("\n处于就绪对列的进程\n");  
	while(p->next!=NULL)  
	{  
		display(p->next);  
		p = p->next;  
	}  
	pcb *q = head1;  
	while(q->next!=NULL)  
	{  
		display(q->next);  
		q = q->next;  
	}  
	sort();  
}  
int main()  
{  
	// 创造进程
	create();  
	pcb * p;  
	// 判断两个对列的进程是否都走完 
	while(head->next!=NULL || head1->next!=NULL)  
	{  
		if(head->next!=NULL)  
		{  
			p= head->next;  
			p->state='R';  
			runpcb(p);  
		}  
		else  
		{  
			arrivetime();  
		}  
	}  
	system("pause");
	return 0;  
}  
2-张萌
/*
*作业:进程状态转换及PCB的模拟
*班级:2016级2班
*学号:2016011424
*姓名:张萌
*/

#include<iostream>
#include <iomanip>        
#include <time.h>
using namespace std;

typedef struct PCB {
	int priority;//优先数
	int arrivetime;//到达时间
	char * name;//进程名称
	int spendtime;//已用CPU时间
	int needtime; //需要的时间
	char status;//进程状态
	struct PCB * next ;
}PCB;

int cputime = 0;
PCB *front = new PCB;    //头指针
PCB *rear = new PCB;     //尾指针

PCB * create(int priority, char *name, int needtime, int arrivetime)
{
		PCB * pcb = (PCB *)malloc(sizeof(PCB));
		pcb->priority = priority;
		pcb->needtime = needtime;
		pcb->name = name;
		pcb->arrivetime = arrivetime;
		pcb->spendtime = 0;
		pcb->next = NULL;
		return pcb;
};
void queue(PCB * pcb)
{
	PCB *t = front;
	if (front->next == NULL)
	{
		front->next = pcb;
		rear = pcb;
	}
	else {
		while (t->next!=NULL)
		{
			if (pcb->priority<=t->priority&&pcb->priority>=t->next->priority ) {
				pcb->next = t->next;
				t->next = pcb;
				break;
			}
			else if (front->next->next==NULL && pcb->priority >= front->next->priority)
			{
				pcb->next = front->next;
				front->next = pcb;
				break;
			}
			else if (front->next->next == NULL && pcb->priority < front->next->priority)
			{
				front->next->next = pcb;
				break;
			}
			front = front->next;
		}
	}
};
	void destroy(PCB * pcb)
	{
		if (front->next)
		{
			front->next = front->next->next;
			pcb->next = NULL;
		}
	}
	int run(PCB * pcb)
	{
		if (front->next == NULL )
		{
			cout << "所有进程均执行完毕\n" << endl;
			return -1;
		}
		destroy(pcb);
		cout << pcb->name << "进入运行状态"<<endl;
		pcb->spendtime++;
		pcb->priority--;
		cputime++;
		if (pcb->needtime == pcb->spendtime)
		{
			cout << pcb->name << "已经执行完"<<endl;
			return 0;
		}
		else {
			queue(pcb);
			cout<<pcb->name<<"已插入就绪队列\n";
			return 0;
		}
	}
	int main(void)
	{
		front->next = NULL;
		front->priority = INT_MAX;
		front->spendtime = 0;
		front->needtime = 0;
		front->name = "123";
		front->arrivetime = 0;
		PCB *arr[3];
		//进程的优先数,需要的时间,到达的时间
		PCB *p1 = create(1, "p1", 3, 0);  
		PCB *p2 = create(3, "p2", 2, 1);
		PCB *p3 = create(2, "p3", 2, 3);
		arr[0] = p1; 
		arr[1] = p2; 
		arr[2] = p3;
		do {
			for (int j = 0; j < 3; j++)
			{
				if (arr[j]->arrivetime == cputime)
				{
					//cout << "新进程到达\n" << endl;
					queue(arr[j]);
				}
			}
		} while (run(front->next)!=-1);

		system("pause");
		return 0;
	}
2-王岑
/*
 班级:2班
 姓名:王岑
 学号:2016011381
*/
#include"stdio.h"
#include<stdlib.h>
#include<conin.h>
#define getpch(type)(type*)malloc(sizeof(type))
#define NULL 0
struct pcb{
	char name[10];
	char state;
	int super;
	int ntime;
	int rtime;
	struct pcb*link;
}*ready=NULL,*p;
typedef struct pcb PCB;

int sort()//建立对进程进行优先级排列函数
{
	PCB *first,*second;
	int insert=0;
	if((ready==NULL)|| ((p->super)>(ready->super)))//优先级最大值,插入队首
	{
		p->link=ready;
		ready=p;
	}
	else//进程比较优先级,插入适当的位置中
	{
		first=ready;
		second=first->link;
		while(second!=NULL)
		{
			if((p->super)>(second->super))//若插入进程比当前进程优先数大
			{//插入到当前的进程前面
				p->link=second;
				first->link=p;
				second=NULL;
				insert=1;
			}
			else//插入进程优先数最低,则插入到队尾
			{
				first=first->link;
				second=second->link;
			}
		}
		if(insert==0)
		{
			first->link=p;
		}
	}
}
int input()//建立进程控制块函数
{
	int a;
	int num;
	clrscr();//清屏
	printf("\n 请输入进程号:");
	scanf("%d",&num);
	for(a=0;a<num;a++)
	{
		printf("\n 进程号No.&d:\n",a);
		p=getpch(PCB);
		printf("\n 请输入进程名字:");
		scanf("%s",p->name);
		printf("\n 请输入进程优先数:");
		scanf("%d",&p->ntime);
		printf("\n");
		p->link=NULL;
		sort();//调用sort()函数
	}
}
int space()
{
	int i=0;
	PCB*pr=ready;
	while(pr!=NULL)
	{
		i++;
		pr=pr->link;
	}
	return i;
}
int disp(PCB *pr)
{
	printf("\n qname \t state \t super \t ndtime \t runtime \n");
	printf("i%s\t",pr->name);
	printf("i%c\t",pr->state);
	printf("i%d\t",pr->super);
	printf("i%d\t",pr->ntime);
	printf("i%d\t",pr->rtime);
	printf("\n");
}
int check()//查看进程函数
{
	PCB*pr;
	printf("\n 当前正在运行的进程是:%s",p->name);
	disp(p);
	pr=ready;
	printf("\n 当前就绪队列状态为:\n");
	while(pr!=NULL)
	{
		disp(pr);
		pr=pr->link;
	}
}
int destroy()//建立进程撤销函数
{
	printf("\n 进程[%s] 已完成\n",p->name);
	free(p);
}
int running()//建立进程就绪函数
{
	(p->rtime)++;
	if(p->rtime==p->ntime)
	{
		destroy();
	}
	else
	{
		(p->super)--;
		p->state='W';
		sort();
	}
}
int main()//主函数
{
	int l,h=0;
	char ch;
	input();
	l=space();
	while((l!=0)&&(ready!=NULL))
	{
		ch=getchar();
		h++;
		printf("\n The execute number:%d \n",h);
		p=ready;
		ready=p->link;
		p->link=NULL;
		p->state='R';
		check();
		running();
		printf("\n 请按任意键继续");
		ch=getchar();
	}
	printf("\n\n 进程已经完成 \n");
	ch=getchar();
}
7-胡宇
/*
	姓名:胡宇
	班级:七班
	学号:2016011651
*/

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<string.h>
using namespace std;

//总进程数
int n=0;
typedef struct PCB{
	//进程名
	char name;
	//优先级
	int priority;
	//到达时间
	int arrivetime;
	//需要运行时间
	int needtime;
	//已用CPU时间
	int cputime;
	//进程状态
	char status;
	struct PCB *next;  
}PCB;
//插入进程
void charu(PCB* a,PCB * b){
	PCB * p,*q;
	p=a;
	if(a->next==NULL)a->next=b;
	else{
		q=p->next;
		while(q){
			if(b->priority > q->priority){
				b->next=q;
				p->next=b;break;
			}
			p=p->next;q=q->next;
		}
		if(!q){p->next=b;b->next=NULL;}

	}
}

//输入PCB数据
void shuru(PCB *a){
	cout <<"请输入进程名:";
	cin >> a->name;
	cout<<"请输入优先数:" ;
	/*cin >>a->priority;
	cout<<"请输入到达时间:" ;*/
	cin >> a->arrivetime;
	cout<<"请输入需要运行时间:" ;
	cin >> a->needtime;
	cout<<"请输入已用CPU时间:";
	cin >> a->cputime;
	/*cout<<"请输入进程状态:" ;
	cin >> a->status;*/
}
//创建队列
PCB* cre(PCB* a){
	PCB *b=new PCB;
	b->next=NULL;
	shuru(b);
	n++;
	charu(a,b);
	return a;
}

//调度算法
void diaodu(PCB *a){
	if(a->next==NULL)cout << "已无进程"<<endl;
	else{
		PCB *p=a->next;
		a->next=p->next;
		if(p->cputime+1==p->needtime){
			free(p);n--;
		}
		else{
			p->priority--;
			charu(a,p);
		}
	}
}
//打印就绪队列
void dayin(PCB *a){
	PCB *p=a->next;
	cout << "----------就绪队列----------"<<endl;
	for(int i=0;i<n;i++){
		cout << "进程名:"<<" "<<p->name <<endl;
		
		p=p->next;
	}
}
int main(void){
	PCB *a =new PCB;
	a->next=NULL;
	int i=1;
	while(i==1){
		int m;
		cout<<"是否输入进程:【1/0】";
		cin >> m;
		if(m==1){a=cre(a);}
		if(m==0)i=0;
	}
	while(n!=0){
		diaodu(a);
		dayin(a);
	}
	

	return 0;
}
#include <iostream>
#include <string>
using namespace std;

typedef struct PCB {
	int ptr;
	int arrive_time;
	char * name;
	int spend_time;
	int need_time; //需要的时间。
	struct PCB * next ;
}PCB;


int CpuTime = 0;
PCB *head = new PCB;    //头指针

PCB *low = new PCB;     //尾指针
PCB * create(int ptr, char *name, int need_time, int arrive_time)
{
	
		PCB * pcb = (PCB *)malloc(sizeof(PCB));
		pcb->ptr = ptr;
		pcb->need_time = need_time;
		pcb->name = name;
		pcb->arrive_time = arrive_time;
		pcb->spend_time = 0;
		pcb->next = NULL;
		return pcb;
};
//void inithead(PCB *head)
//{
//	head = (PCB*)malloc(sizeof(PCB));
//	head->ptr = INT_MAX;
//}
void queue(PCB * pcb)
{
	
	PCB *t = head;
	if (head->next == NULL)
	{
		head->next = pcb;
		low = pcb;
		
	}
	else {
		
		while (t->next!=NULL)
		{
			if (pcb->ptr<=t->ptr&&pcb->ptr>=t->next->ptr ) {
				pcb->next = t->next;
				t->next = pcb;
				
				break;
			}
			else if (head->next->next==NULL && pcb->ptr >= head->next->ptr)
			{
				pcb->next = head->next;
				head->next = pcb;
				
				break;
			}
			else if (head->next->next == NULL && pcb->ptr < head->next->ptr)
			{
				head->next->next = pcb;
				break;
			}
			head = head->next;
		}
	}
	
		
	
};
	void remove(PCB * pcb)
	{
		if (head->next)
		{
			head->next = head->next->next;
			pcb->next = NULL;
		}
	}
	int run(PCB * pcb)
	{
		
		if (head->next == NULL )
		{
			cout << "所有进程均已执行完毕" << endl;
			return -1;
		}
		
		remove(pcb);
		
		cout << pcb->name << "去cpu运行"<<endl;
		pcb->spend_time++;
		pcb->ptr--;
		CpuTime++;
		
		if (pcb->need_time == pcb->spend_time)
		{
			cout << pcb->name << "已经执行完了"<<endl;
			
			return 0;
		}
		else {
			queue(pcb);
			printf("%s已经重新插入就绪队列\n", pcb->name);
			return 0;
		}
	}
	int main(void)
	{
		head->next = NULL;
		head->ptr = INT_MAX;
		head->spend_time = 0;
		head->need_time = 0;
		head->name = "123";
		head->arrive_time = 0;
		PCB *arr[3];
		PCB *p1 = create(2, "p1", 2, 0);  //优先级,需要的时间,到达的时间
		PCB *p2 = create(3, "p2", 2, 0);
		PCB *p3 = create(2, "p3", 4, 3);
		arr[0] = p1; arr[1] = p2; arr[2] = p3;
		
		
		do {
			for (int j = 0; j < 3; j++)
			{
				if (arr[j]->arrive_time == CpuTime)
				{
					cout << "新的进程到达" << endl;
					
					queue(arr[j]);
					

				}
			}
		} while (run(head->next)!=-1);
		system("pause");
	
	}
	

不好意思老师,我运行图片忘记交啦

5-闵俨
#include <stdio.h>  
#include <stdlib.h>  
  
typedef struct pcb  
{  
    int name; 
    char state; 
    int arrivetime; 
    int usetime;
    int cputime;
    int count;
    struct pcb *next;  
}pcb;  
pcb *head = NULL; 
pcb *head1= NULL; 
int n = 0;// 
void createhead()  
{  
    pcb *p = (pcb*)malloc(sizeof(pcb));
    head = p;  
    pcb *q = (pcb*)malloc(sizeof(pcb));
    head1 = q;  
}  
void sort()
{  
    pcb* t = head;  
    pcb *q,*p,*r;  
    int min;  
    while(t->next != NULL)  
    {  
        p = t->next;  
        r = t->next;  
        min = r->count;  
        while(r!= NULL)  
        {  
            if(r->count > min)  
            {  
                min = r->count;  
                p = r;  
            }  
            r = r->next;  
        }
        q = t;  
        while (q->next != p)  
            q = q->next;  
        if(t->next != p)  
        {  
            q->next = p->next;  
            p->next = t->next;  
            t->next = p;  
        }
        t = t->next;  
    }  
}  
bool create()
{  
    createhead();  
    pcb *p = head1;  
    pcb *q = head;  
    printf("请输入进程数目:");  
    scanf("%d",&n);  
    pcb *temp;  
    for(int i=1;i<=n;i++ )
    {  
        temp = (pcb*)malloc(sizeof(pcb));  
        if(!temp) return false;  
        printf("请输入进程%d的运行时间,进程优先数,到达时间:",i);  
        scanf("%d %d %d",&(temp->usetime),&(temp->count),&(temp->arrivetime));  
        temp->cputime = 0;  
        temp->name=i;  
        temp->next = NULL;  
        temp->state='A';  
        if(temp->arrivetime!=0) // 对到达时间进行判断  
        {  
            q->next = temp;  
            q = temp;  
        }  
        else  
        {  
            p->next = temp;  
            p = temp;  
        }  
    }  
    sort();
    return true;  
}  
void destory(pcb *rb)
{  
    printf("****************进程%d已完成****************\n",rb->name);  
    pcb *q = rb->next;  
    head->next = q;  
    free(rb);  
}  
void display(pcb *rp)   
{  
    printf("进程名字:%d",rp->name);  
    printf("\n进程优先级:%d",rp->count);  
    printf("\n进程所占时间片:%d",rp->usetime);  
    printf("\n进程已运行时间:%d",rp->cputime);  
    printf("\n进程当前状态:%c",rp->state);  
    
}  
void arrivetime()
{  
    pcb *q = head1->next;  
    pcb *r,*t;  
    while(q!=NULL) 
    {  
        q->arrivetime--;  
        if(q->arrivetime==0)  
        {  
            t = head1;  
            while(t->next!=q)  
                t = t->next;  
            t->next = q->next;  
            r = head->next;  
            q->next = r;  
            head->next = q;  
        }  
        q = q->next;  
    }  
}  
void runpcb(pcb *rp)  
{  
    rp->cputime++; 
    arrivetime();  
    printf("----------正在运行的进程----------\n");
    display(rp);  
    if(rp->cputime==rp->usetime)  
    {  
        destory(rp);  
    }  
    else  
    {  
        rp->count--;  
        rp->state = 'A';  
    }  
    pcb *p = head;  
    if(head->next==NULL&&head1->next==NULL) return;  
    printf("----------处于就绪对列的进程----------\n");  
    while(p->next!=NULL)  
    {  
        display(p->next);  
        p = p->next;  
    }  
    pcb *q = head1;  
    while(q->next!=NULL)  
    {  
        display(q->next);  
        q = q->next;  
    }  
    sort();  
}  
int main()  
{  
    create();
    pcb * p;  
    while(head->next!=NULL || head1->next!=NULL)
    { 
        if(head->next!=NULL)  
        {  
            p= head->next;  
            p->state='R';  
            runpcb(p);  
        }  
        else  
        {  
            arrivetime();  
        }  
    }  
    return 0;  
}  
8-刘江
/*
姓名:刘江
班级:八班
学号:2572707156
*/
#include<stdio.h>
#include<string.h>
#include<time.h>
#define N 3
typedef struct jcb{
    char name[10];//进程名
    int reqtime;//要求服务时间
    int prio;//优先级
    int runtime;//运行时间 
    char status;
}PCB;
int intarr=0,intfin=0;//到达进程个数,完成进程个数
PCB pcbarr[24],pcbfin[24];

void Mune()
{
    printf("\n\n");
    printf("\t\t|------------------------------------------------|\n");
    printf("\t\t|                 进程调度模拟程序               |\n");
    printf("\t\t|------------------------------------------------|\n");
    printf("\t\t|       0:退出                                   |\n");
    printf("\t\t|       1:运行(最高优先级优先算法)             |\n");
    printf("\t\t|       2:插入                                   |\n");
    printf("\t\t|       3:删除                                   |\n");
    printf("\t\t|------------------------------------------------|\n");
    printf("请选择<0~3>:");
}
void Input()//手动输入
{
    int i;
    int n=0;
    printf("请输入进程个数:");
    scanf("%d",&n);
    for(i=0;i<n;i++,intarr++)
    {
        printf("\n第%d个进程:\n请输入进程名:",i+1);
        scanf("%s",pcbarr[intarr].name);
        printf("请输入要求服务时间:");
        scanf("%d",&pcbarr[intarr].reqtime);
        pcbarr[intarr].prio=N;//优先级为3
        if(i==0)
            pcbarr[intarr].status='r';
        else
            pcbarr[intarr].status='w';
    }
}

void Output()//输出排序后队列
{
    int i=0;
    printf("\n\n运行队列的是\n");
    printf("\tname\treqtime\truntime\tprio\tstatus\n");
    if(intarr!=0){
    printf("N%d\t%s\t%d\t%d\t%d\t%c\n",i,pcbarr[i].name,pcbarr[i].reqtime,pcbarr[i].runtime,pcbarr[i].prio,pcbarr[i].status);
    }
    printf("\n就绪队列的是\n");
    printf("\tname\treqtime\truntime\tprio\tstatus\n");
    for(i=1;i<intarr;i++){
        printf("N%d\t%s\t%d\t%d\t%d\t%c\n",i,pcbarr[i].name,pcbarr[i].reqtime,pcbarr[i].runtime,pcbarr[i].prio,pcbarr[i].status);
    }
    printf("\n已完成队列的是\n");
    printf("\tname\treqtime\truntime\tprio\tstatus\n");
    for(i=0;i<intfin;i++){
        printf("N%d\t%s\t%d\t%d\t%d\t%c\n",i,pcbfin[i].name,pcbfin[i].reqtime,pcbfin[i].runtime,pcbfin[i].prio,pcbfin[i].status);
    }
    printf("\n*********************************************\n");
}

//按优先级排序
void Sort()
{
    int i,j;
    PCB temp;
    for(i=0;i<intarr-1;i++)
    {
        for(j=i+1;j<intarr;j++)
        {
            if(pcbarr[i].prio<pcbarr[j].prio)
            {
                temp=pcbarr[i];
                pcbarr[i]=pcbarr[j];
                pcbarr[j]=temp;
            }
        }
    }
    pcbarr[0].status='r'; 
    for(i=1;i<intarr;i++)
    {
        pcbarr[i].status='w';
    }
}
void running()
{ 
  int slice,i,k;
  slice=1;

  for(i=1;i<((N+1)-pcbarr[0].prio);i++)
    slice=slice*2;
    
  for(i=1;i<=slice;i++)
  {
     pcbarr[0].runtime++; 
     if (pcbarr[0].runtime==pcbarr[0].reqtime)
       break;
       
  }
  if(pcbarr[0].runtime==pcbarr[0].reqtime) 
  {
      printf("\n 进程 [%s] 已完成.\n",pcbarr[0].name); 
      pcbfin[intfin]=pcbarr[0];
      for(k=0;k<=intarr;k++)
      {
        pcbarr[k]=pcbarr[k+1];
      }
      intarr--;
      intfin++;
  }
  else 
  { 
    if(pcbarr[0].prio>1) pcbarr[0].prio--; 

  } 
} 

void Delete()
{
    char b[20];
    int i,j,key=0;
    printf("请输入要删除的进程名:");
    scanf("%s",b);
    for(i=0;i<intarr;i++)
    {
        if(strcmp(b,pcbarr[i].name)==0)
         {
            key=1;
            for(j=i;j<=intarr;j++)
            {
                  pcbarr[j]=pcbarr[j+1];

            }    
            intarr--;
         }
     }
     for(i=0;i<intfin;i++)
    {
        if(strcmp(b,pcbfin[i].name)==0)
        {
            key=1;
            for(j=i;j<=intfin;j++)
            {
                pcbfin[j]=pcbfin[j+1];

            }
            intfin--;
        }
    }
       if(key==0)
       {
           printf("查找不到该进程!");
       }
}
main()
{
    int chose;
    Input();
    Output();
    while(1)
    {
        Mune();
        scanf("%d",&chose);
        switch(chose)
        {
        case 0:exit(0);break;
        case 1:running();break;
        case 2:Input();break;
        case 3:Delete();break;
        default:printf("输入错误!");
        }
        Sort(); 
        Output();
    }
}
1-黄鹏
/* 
姓名:黄鹏
班级:1班 
学号:2016011347
*/
#include<stdio.h>
#include<stdlib.h>
typedef struct pcb{
	char name[10];//进程名称
	int arrivetime;//进程到达时间
	int count;//优先数
	int dotime;//进程运行时间
	int cputime;//占用cpu时间
	char state;//进程状态
	struct pcb *next;
}pcb;
pcb*head=(pcb*)malloc(sizeof(pcb));
pcb*head1=(pcb*)malloc(sizeof(pcb));
void sort()
{
	pcb*t=head;
	pcb *q,*p,*r;
	int max;
	while(t->next!=NULL)
	{
		q=head;
		p=t->next;
		r=t->next;
		max=r->count;
		while(r!=NULL)
		{
			if(r->count>max){
				max=r->count;
				p=r;
			}
			r=r->next;
		}
		q=t;
		while (q->next != p)  
            q = q->next;  
        if(t->next != p)  
        {  
            q->next = p->next;  
            p->next = t->next;  
            t->next = p;  
        }// 插入进行排序按照优先数  
		t=t->next;
	}
}
bool create(){//创建进程函数
	pcb*q=head;
	pcb*p=head1;
	printf("请输入进程的数量:");
	int n;
	scanf("%d",&n);//进程的数量
	for(int i=0;i<n;i++){
		pcb* temp=(pcb*)malloc(sizeof(pcb));
		if(temp)	return false;
		printf("进程名称:");
		scanf("%s",&(temp->name));
		printf("进程到达时间:");
		scanf("%d",&(temp->arrivetime));
		printf("优先数:");
		scanf("%d",&(temp->count));
		printf("进程运行时间:");
		scanf("%d",&(temp->dotime));
		printf("占用cpu时间:");
		scanf("%d",&(temp->cputime));
		printf("进程状态:");
		scanf("%s",&(temp->state));
		if(temp->arrivetime=0)
		{
			q->next=temp;
			q=temp;
		}
		else{
			p->next=temp;
			p=temp;
		}
	}
	sort();
	return true;
}
void arrivefunction()
{
	pcb*q=head1->next;
	pcb*t;
	while(q->next!=NULL)
	{
		q->arrivetime--;
		if(q->arrivetime==0)
		{
			t=head1;
			while(t->next!=q)
			{
				t=t->next;
			}
			t->next=q->next;
			q->next=head->next;
			head->next=q;
		}
		q=q->next;
	}
}
void display(pcb*pro)
{
	printf("进程名称:%s",pro->name);
	printf("进程优先数:%d",pro->count);
	printf("进程所占时间片:%d",pro->dotime);
	printf("进程已运行时间:%d",pro->cputime);
	printf("进程当前状态:%s",pro->state);
}
void destory(pcb*pro)
{
	pcb *q = pro->next;  
    head->next = q;  
    free(pro);  
}
void cpufunction(pcb*pro)
{
	pro->cputime++;
	arrivefunction();
	printf("正在运行的进程");
	display(pro);
	if(pro->cputime==pro->dotime)  
    {  
        destory(pro);  
    }  
    else  
    {  
        pro->count--;  
        pro->state = 'W';  
    }  
    pcb *p = head;  
    if(head->next==NULL&&head1->next==NULL) return;  
    while(p->next!=NULL)  
    {  
        display(p->next);  
        p = p->next;  
    }  
    pcb *q = head1;  
    while(q->next!=NULL)  
    {  
        display(q->next);  
        q = q->next;  
    }  
    sort();  
}
int main(){
	create();
	pcb*pro;
	while(head->next!=NULL || head1->next!=NULL) // 判断两个对列的进程是否都走完  
    {  
        if(head->next!=NULL)  
        {  
            pro= head->next;  
            pro->state='R';  
            cpufunction(pro);  
        }  
        else  
        {  
            arrivefunction();  
        }  
    }  
    return 0;  
}
/*
*进程状态转换及PCB的模拟
*2016级5班
*2016011537
*郑宁宁
*/

#include<iostream>
#include <stdlib.h>        
#include <time.h>
using namespace std;

//优先级:p_priority大的优先级高
struct PCB{
    int p_priority;                  //优先数
    //int p_atime;                   //到达时间
    int p_rtime;                    //需要运行时间
    int p_cpu;                       //已占CPU时间
    char p_name;         //进程名
    char p_state;         //进程状态:Wait、Run、Finish
    PCB *next;          //指向下一个PCB
};

struct Link{
    PCB*front;  //队头指针
    PCB* rear;   //队尾指针
};



bool InitQueue(Link * P) //构造一个空就绪队列
{
    P->front=P->rear =new PCB;
    P->front->next=NULL;
    return true;
}

void EnQueue(Link * P,PCB*e_pcb)//插入元素
{
    if(P->front->next==NULL)
    {
        P->front->next=e_pcb;
        e_pcb->next=NULL;
    }
    else
    {
        PCB*p=P->front->next;
        while(p->next!=NULL){
            p=p->next;
        }
        p->next=e_pcb;
        e_pcb->next=NULL;
        /*while(p->next->p_priority > e_pcb->p_priority)
        {
            p=p->next;
        }
        e_pcb->next=p->next;
        p->next=e_pcb;*/
    }
}

void DeQueue(Link * P,PCB*e_pcb) //将进程从就绪队列中删除
{
    if(e_pcb->next==NULL)
    {
         P->front->next=NULL;
    }
    else
    {
        P->front->next=e_pcb->next;
    }
}

char RunState(PCB*e_pcb){//进程状态改变
    if(e_pcb->p_cpu==0)
        e_pcb->p_state='W';
    else if(e_pcb->p_cpu<e_pcb->p_rtime)
        e_pcb->p_state='R';
    else
        e_pcb->p_state='F';
    return e_pcb->p_state;
}


int main(void){

    PCB*p1=new PCB;
    p1->p_priority = 4;
    p1->p_rtime=3;    
    p1->p_name='f';
    p1->p_state='W';
    p1->p_cpu=0;

    PCB*p2=new PCB;
    p2->p_priority=2;
    p2->p_rtime=2;
    p2->p_name='s';
    p2->p_state='W';
    p2->p_cpu=0;


    Link R;
    InitQueue(&R);
    EnQueue(&R,p1);
    EnQueue(&R,p2);

      PCB*tempt=R.front->next;
      do{
        cout<<"进程名称"<<tempt->p_name<<endl;  //名称
        cout<<"优先数"<<tempt->p_priority<<endl;    //优先数
        cout<<"运行时间"<<tempt->p_rtime<<endl;   //运行时间
        cout<<"运行状态"<<tempt->p_state<<endl;   //运行状态
        cout<<"已运行时间"<<tempt->p_cpu<<endl; //已运行时间
        tempt->p_cpu++;   
        tempt->p_priority--;
        RunState(tempt);
        cout<<"时间片运行过后: "
            << "优先数: "<< tempt->p_priority
            <<"; 已运行时间:  "<< tempt->p_cpu
            <<"; 运行状态: "<<tempt->p_state <<endl;
        if(tempt->p_cpu < tempt->p_rtime){
            DeQueue(&R,tempt);
            EnQueue(&R,tempt);
        }
        else{
            DeQueue(&R,tempt);
        }
            tempt=R.front->next;
    }while(1);


    return 0;
}
//姓名:王碧云
//班级:3班
//学号:2016011456


#include <iostream>
#include <string>
using namespace std;

typedef struct PCB
{
	string name;//进程名
	int priority;//优先数
	int arrivetime;//到达时间
	int runtime;//需要运行时间
	int usedtime;//已用CPU时间
	string state;//进程的状态(W/R/F)
	struct PCB * next;
}*ptrPCB;

//初始化PCB
void InitializeList(ptrPCB & L)
{
	L=new PCB();
	L->next=NULL;
}



//按优先数优先进行排序
void inserSort(ptrPCB & L)
{
	if(!L->next || !L->next->next)
		return;
	else
	{
		ptrPCB p=L->next;
		ptrPCB q=p->next;
		p->next=NULL;
		ptrPCB s;
		while(q)
		{
			ptrPCB t=L->next;
			ptrPCB h=L;
			while(t && q->priority<t->priority)
			{
				h=t;
				t=t->next;
			}
			s=q->next;
			q->next=h->next;
			h->next=q;
			q=s;
		}
	}
}


//链表中进程的个数
int Length(ptrPCB & L)
{
	int i=0;
	ptrPCB p=L->next;
	while(p)
	{
		p=p->next;
		i++;
	}
	return i;
}

//打印输出进程信息
void printLn(ptrPCB L)
{
	ptrPCB p=L->next;
	while(p)
	{
		cout<<"进程名"<<p->name<<"  "
			<<"优先数"<<p->priority<<"  "
			<<"到达时间"<<p->arrivetime<<"  "
			<<"已用CPU时间"<<p->usedtime<<"  "
			<<"需要运行时间"<<p->runtime<<"  "
			<<"运行状态"<<p->state<<"  "
			<<endl;
		p=p->next;
	}
	cout<<endl;
}

//建立进程撤销函数
void Destory(ptrPCB & L)
{
	cout<<"进程已完成"<<endl;
	free(L);
}


int mian(void)
{
	ptrPCB wait;//就绪队列
	ptrPCB run;//运行队列
	ptrPCB finish;//完成队列

	//初始化队列
	InitializeList(wait);
	InitializeList(run);
	InitializeList(finish);

	//输入进程信息
	int sum;//进程的个数
	cout<<"输入进程的个数:"<<endl;
	cin>>sum;
	for(int i=0;i<sum;i++)
	{
		ptrPCB p=new PCB();
		cout<<"请输入第"<<i+1<<"个进程的进程名、优先数、到达时间、需要运行时间";
		cin>>p->name>>p->priority>>p->arrivetime>>p->runtime;
		p->state="run";
		p->usedtime=0;
		p->next=run->next;//将进程插入
		run->next=p;
	}

	//各进程按优先数从高到低排列
	inserSort(wait);
	inserSort(run);
	inserSort(finish);

	
	while(!Length(wait))//判断就绪队列是否为空
	{
		ptrPCB p=run;
		while(p->next)
		{
			p=p->next;
		}
		p->next=wait->next;//就绪队列首进程投入运行
		(run->usedtime)++;//时间片到,运行进程已占用cpu时间+1
		if(run->usedtime==run->runtime)
		{
			//已到达,进程完成撤销该进程
			Destory(run);
		}
		else
		{
			//未到达
			(run->priority)--;//使运行进程的优先数减一
			ptrPCB q=wait;
			while(q->next)
			{
				q=q->next;
			}
			q->next=run->next;//将运行进程插入就绪队列
		}


	}


	return 0;
}

老师对不起,程序无法运行成功,没有截图。