process

//時間輪轉最多 輪轉
#include<iostream>
#include<queue>
using namespace std;
struct node
{
    friend bool operator< (node n1, node n2)
    {
        if(n1.t1<n2.t1)
   return false;
  if(n1.t1==n2.t1)
  {
   if(n1.t2<n2.t2)
    return true;
   if(n1.t2>n2.t2)
    return false;
  }
  return true;
    }
    int t1;//做業的到達時間
    int t2;//做業的運行時間
 int p;//進程的優先級
 char name[10];
};
struct Process//進程結構體
{
 char name[10];
 int t;//運行時間
 int p;//進程優先級
 bool s;//進程的狀態
 Process *next;
};
int clock;
priority_queue<node> q;
void creat_work()//做業隨機產生隨機個數的做業
{
 int x=(rand()%10);
 while(x--)
 {
  clock=(clock+1)%1000;
  node work;node

  work.name[0]=(rand()%128);
  work.name[1]=(rand()%128);
  work.name[2]=(rand()%128);
  work.name[3]=(rand()%128);ios

  work.t1=(rand()%1000);
  work.t2=(rand()%1000);
  work.p=(rand()%1000);
  clock+=3;
  clock%=1000;
  q.push(work);
 }
}
void creat_process()
{spa

 

}
int main()
{
    creat_work();//產生做業
 clock=0;
 creat_process();//產生進程;
 進程


 return 0;it

}io

相關文章
相關標籤/搜索