五、 程序及注释
#include
struct pcb { };
typedef struct pcb PCB; 以后都可以用PCB去定义
//各子程序的声明 void *creat(int n);
//将struct pcb定义为新的数据类型PCB,这样
char name[10]; int come_time; int run_time; int VIP;
//进程名 //进程到达时间 //运行时间 //优先级
//定义名为pcb的结构体
struct pcb *next; //链表指针
void Firstcome_Firstserve(PCB *head); void Menue(PCB *head,int n); void*My_Copy(PCB *head); void Print( PCB *head,int len);
void TimeTurn_Firstserve(PCB *head,int timeturn,int n); void VIP_Firstserve(PCB *head);
/************************************************************************/
/* *创建进程就绪队列链表* */
/************************************************************************/
void *creat(int n) {
PCB *head,*p,*q;
assert (head=(PCB*)malloc(sizeof(PCB)));
//malloc函数向系统
申请分配sizeof(PCB)个字节的内存空间
息
getchar(); gets(q->name);
puts(\进程开始时间\p=head; p->next=NULL;
while(n--) {
p=head;
if( ( q=(PCB*)malloc(sizeof(PCB))) == NULL) { }
puts(\进程名:\
//开始读入PCB的信
printf(\exit(0);
}
}
scanf(\puts(\进程运行时间\scanf(\puts(\优先级\scanf(\if(p->next==NULL) { } else {
while (p->next!=NULL && q->come_time >p->next->come_time ) { }
q->next=p->next; p->next=q;
q->next=NULL; p->next=q;
//在插入节点时排序
p=p->next;
}
return head;
/************************************************************************/
/* 拷贝链表 */
/************************************************************************/
void *My_Copy(PCB *head1) { }
/********************************打印就绪队列链表
PCB *head2=NULL; PCB *p2=NULL; PCB *p1=head1->next; PCB *node=NULL;
assert(head2=(PCB*)malloc(sizeof(PCB))); p2=head2;
while(p1!=NULL) { }
return head2;
assert(node = (PCB*)malloc(sizeof(PCB)));
strcpy(node->name,p1->name); node->come_time=p1->come_time; node->run_time=p1->run_time; node->VIP=p1->VIP;
node->next=NULL; p2->next=node;
p2=p2->next; p1=p1->next;
//p1、p2指针后移
//拷贝进程
//新链表头结点
*****************************************/
void Print( PCB *head,int len) {
printf(\
puts(\进程名 到达时间 运行时间 优先级\for(i=0;i
head=head->next; int i=0;
,head->VIP);
}
/************************************************************************/
/* *时间片轮转算法* */
/************************************************************************/
void TimeTurn_Firstserve(PCB *head,int timeturn,int n) {
PCB *Head=My_Copy(head); PCB *p; int time;
}