?? 時間片.cpp
字號:
#include "stdafx.h"
#include <iostream.h>
struct pcb
{
char q;
int atime;
int btime;
char state;
struct pcb *next;
} ;
char proc[5]={'a','b','c','d','e'};
int a[5]={4,3,5,2,4};
pcb *link(char proc[],int a[],int n)
{
pcb *head,*r,*p;
for(int i=0;i<n;i++)
{
p=(pcb *)new(pcb);
p->q=proc[i];
p->atime=a[i];
p->btime=0;
p->state='r';
p->next=NULL;
if (i==0)
{
head=p;r=p;
}
else
{
r->next=p;r=p;
}
}
r->next=head;
return head;
}
void deal(pcb *h,int n)
{
pcb *r,*s,*p;
r=h;s=h;
int j=5;
int flag=0;
for(int i=0;i<n;i++)
{
cout <<"第"<<i+1<<"次運行的過程:"<<endl;
for(int f=0;f<flag;f++)
{j-=1;}
flag=0;
for(int i=0;i<j;i++)
{
if (j==0) {break;}
s->btime=s->btime+1;
if (s->btime==s->atime)
{
s->state='e';
p=s;
r->next=p->next;
cout<<s->q<<' '<<s->atime<<' '<<s->btime<<' '<<s->state<<' '<<s->q<<"運行完"<<endl;
s=s->next;
delete p;
flag+=1;
}
else
{
r=s;
s=s->next;
cout<<r->q<<' '<<r->atime<<' '<<r->btime<<' '<<r->state<<' '<<endl;
}
}
}
}
void main()
{
pcb *head;
head=link( proc, a,5);
deal(head, 5);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -