有错!但不会改!我用的环境是VC6,哪位高手给看看,无限感激!

本文介绍了一个使用C++实现的简单进程调度模拟程序。该程序定义了进程控制块(PCB)结构体,用于存储进程信息,并通过队列管理就绪队列和完成队列。程序还实现了初始化进程、队列的操作及基本的调度逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值