#include <string>
using namespace std;
struct node{
string name;
int arrive_time;
int server_time;
int finish_time;
int priority;
int zt;//周转时间
struct node *next;
};
 
int main()
{
  struct node* pcb=new node();
   int c;
    cout<<"1.创建进程-----------2.查看进程"<<endl;
   cout<<"3.先来先服务---------0.退出"<<endl;
   while(cin>>c){
    if(c==1){
        int t=1;
        struct node* temp =pcb;
        while(t){
        temp->next=new node();
          cout<<"请输入进程的名字"<<endl;
          cin>>temp->name;
        cout<<"请输入进程的到达时间"<<endl;
        cin>>temp->arrive_time;
        cout<<"请输入进程服务时间"<<endl;
        cin>>temp->server_time;
        cout<<"请输入进程的优先级"<<endl;
        cin>>temp->priority;
        cout<<"是否还有其它进程(0/1)"<<endl;
        cin>>t;
        temp=temp->next;
    }
    }else if(c==2){
    node*p=pcb;
    while(p!=NULL){
        cout<<"到达时间"<<p->arrive_time<<endl;
        p=p->next;
    }
    }else if(c==3){
        node*p=pcb;
        int last_finish_time=0;
        int num_zt=0,i=0;
         cout<<"进程名字--到达时间--服务时间--优先级--完成时间--周转时间"<<endl;
        while(p->next!=NULL){
            p->finish_time=last_finish_time+p->server_time;
            last_finish_time= p->finish_time;
            p->zt=p->finish_time-p->arrive_time;
            num_zt+=p->finish_time-p->arrive_time;
            cout<<p->name<<"         "<<p->arrive_time<<"         "<<p->server_time<<"         "<<p->priority<<"        "<<p->finish_time<<"        "<<p->zt<<endl;
            p=p->next;
            i++;
        }
cout<<"平均周转时间"<<num_zt/i<<endl;
    }else if(c==0){
    break;
    }
   }
    return 0;
}```
posted on 2025-03-13 11:38  .forward  阅读(7)  评论(0)    收藏  举报