static int time2=0;
p=head->next; while(p!=NULL) {
//time2为完成标志位,对完成的进程的计数位
//判断进程就绪队列是否为空
if(p->run_time!=0 && p->run_time<=timeturn) //若剩
余运行时间不为0,且剩余运行时间不大于时间片,则执行以下指令
{
time=p->run_time;
printf(\进程:%-5s 到达时间:%-5d,剩余运行时间:%-5d,优先
级:%d\\n\
while(time) { } puts(\p->run_time=0; time2++;
//time2自加,表示已完成进程
printf(\正在执行 %d \\r\time--; Sleep(1000);
多了一个
} else
if(p->run_time!=0 && p->run_time>timeturn)
//若剩
余运行时间不为0,且剩余运行时间大于时间片,则执行以下指令
{
time=timeturn;
printf(\进程:%-5s到达时间:%-5d,剩余运行时间:%-5d,优先
级:%d\\n\
while(time)
{ } puts(\
p->run_time -= timeturn;
//run_time被置为了
printf(\正在执行 %d \\r\time--; Sleep(1000);
runtime-timeturn
算法
}
/************************************************************************/
/* *优先级优先* */
/************************************************************************/
void VIP_Firstserve(PCB *head) {
PCB *Head=My_Copy(head);
return; }
}
p=p->next; if(p==NULL) { }
if(time2==n)
//若所有的进程都已完成,则退出本
p=head->next;
建
PCB *Head_Link;//建新队列
PCB *Link,*node;//建节点,在新队列中会用到。 PCB *flg;//标记指针的位置 PCB *p,*q; static int flag0;
int time_over; //进程结束时间 int time1;
p = Head; q = p->next;
assert(Head_Link = (PCB*)malloc(sizeof(PCB))); //新队列的头结点的创
Head_Link->next = NULL;
while(q->next != NULL) {
if(q==Head->next) {
if(flag0==0) {
printf(\进程:%-5s正在运行,到达时间:%-5d,运行时间:%-5d,
优先级:%d\\n\
while(time_over) {
time_over=q->run_time;
printf(\正在执行 %d \\r\Sleep(1000);
}
puts(\执行完毕!\
flag0++;
}// end of if(flag0==0) else if(flag0==1) {
if(q->next->come_time > q->run_time) //等待下一个进程 {
time1 = q->next->come_time - q->run_time; //等待时间 puts(\while(time1) { }
printf(\time1--; Sleep(1000);
printf(\进程:%-5s正在运行,到达时间:%-5d,运行时
间:%-5d,优先
级:%d\\n\
time_over = q->next->run_time; while(time_over) { }
puts(\执行完毕!\
printf(\正在执行 %d \\r\time_over--; Sleep(1000);
p = q; q = q->next;
} //end of if (q->next->come_time > q->run_time) else if(q->next->come_time <= q->run_time) //将 在q进程
执行完之前,就进入的进程入队。
time_over))
点
节点
节点
节点
节点
{ time_over = q->run_time;
while((q->next != NULL) && (q->next->come_time < {
assert(node=(PCB*)malloc(sizeof(PCB))); //建节
node->come_time=q->next->come_time;
//拷贝
strcpy(node->name,q->next->name);
//拷贝
node->run_time=q->next->run_time;
//拷贝
node->VIP=q->next->VIP;
//拷贝
//插入 法按短作业升序 插入节点, if(Head_Link->next == NULL) { flg = q;//标记 node->next = NULL; Head_Link->next = node;
}
else