#include <iostream.h>
#include <math.h>
#define N 6
int posi[50];
int temp = 0;
typedef struct node
{
char name; //进程名
double prio; //优先权
int arritime; //到达时间
int waittime; //等待时间
int cputime; //运行时间
char state; //进程状态
struct node *next;
}PCB;
PCB p[N];
typedef struct Qnode
{
PCB p[N];
int front;
int rear;
}sequeue;
sequeue *ready,*finish;
void iniPCB(PCB p[])
{
for(int i=1; i<=5; i++)
{
cout<<"进程"<<i<<endl;
cout<<" "<<"进程名: ";
cin>>p[i].name;
cout<<" "<<"到达时间:";
cin>>p[i].arritime;
cout<<" "<<"运行时间:";
cin>>p[i].cputime;
cout<<" "<<"进程状态:";
cin>>p[i].state;
}
}
void iniready(sequeue *ready)
{
ready->front = 0;
ready->rear = 0;
}
int empty(sequeue *ready)
{
if(ready->front = ready->rear)
return 0;
else
return 1;
}
PCB outready(sequeue *ready)
{
if(empty(ready))
{
ready->front = ready->front + 1;
return ready->p[ready->front];
}
}
void inifinish(sequeue *finish)
{
finish->front = 0;
finish->rear = 0;
}
void inready(sequeue *ready,PCB p[N])
{
for(int i=1; i<=5; i++)
{
ready->rear = ready->rear + 1;
ready->p[ready->rear] = p[i];
}
}
void getFirst(sequeue *ready)
{
PCB q[N];
int temp = 0;
for(int i=5; i>=1; i--)
{
posi[i]=i;
}
for(i=5; i>=1; i--)
{
if(ready->p[i].arritime < ready->p[i-1].arritime)
{
q[i] = ready->p[i];
ready->p[i] = ready->p[i-1];
ready->p[i-1] = q[i];
temp = posi[i];
posi[i] = posi[i-1];
posi[i-1] = temp;
}
}
}
void main()
{
iniPCB(p);
iniready(ready);
inready(ready,p);
inifinish(finish);
getFirst(ready);
outready(ready);
cout<<"进程"<<temp<<endl;
cout<<" "<<"进程名: ";
cin>>p[temp].name;
cout<<" "<<"到达时间:";
cin>>p[temp].arritime;
cout<<" "<<"运行时间:";
cin>>p[temp].cputime;
cout<<" "<<"进程状态:";
cin>>p[temp].state;
}