91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 2KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-27
  • 語言: 其他
  • 標簽:

資源簡介

進程調度模擬設計--先來先服務、強占式短進程優先算法

資源截圖

代碼片段和文件信息


#include
#include
using?namespace?std;
struct?PCB
{
string?name;//進程名
int?ta;//進程到達時間
int?ts;//進程估計運行的時間
int?tb;//進程開始運行時間
int?tm;//進程仍需運行的時間
int?to;//進程完成的時間
int?rn;//進程運行的次數
int?totalTime;//周轉時間
double?weightTotalTime;//帶權周轉時間(周轉時間/估計運行時間)
PCB?*next;//定義指向下一個進程的指針
};

string?pname[100];//保存進程調度隊列
int?pronum;//定義進程數為pronum
int?total;//記錄所有進程的總周轉時間
double?weight;//記錄所有進程的帶權周轉時間

PCB?*create(PCB?*head);//創建進程隊列
void?del(PCB?*p);//刪除p的下一個節點
void?sort(PCB?*head);//將進程按到達的先后順序排列
int?getCount(PCB?*headint?time);//察看在time之前到達但未移動到運行隊列的進程數量
void?FCFS(PCB?*head);//先來先服務算法
PCB?*SJF(PCB?*headint?count);//在頭節點后的count個節點中選擇需時間最小的返回
void?SJFrun(PCB?*head);//強占式短進程優先算法

void?main()
{
int?choice;
cout<<“*進程調度模擬設計——先來先服務、強占式短進程優先算法*“< cout<<“***********1.先來先服務算法***************************“< cout<<“***********2.強占式短進程優先算法*********************“< cout<<“***********3?退出*************************************“<l1: cout<<“請輸入您的選擇:“<l2: cin>>choice;
PCB?*head=NULL;
switch(choice)
{
case?1:head=create(head);FCFS(head);goto?l1;
case?2:head=create(head);SJFrun(head);goto?l1;
case?3:break;
default:cout<<“輸入錯誤!\n請重新輸入:“< }
}

PCB?*create(PCB?*head)
{
PCB?*p1*p2;
p1=p2=new?PCB;
head=p1;
cout<<“請輸入進程數:“;
cin>>pronum;
for(int?i=0;i {
p2=p1;
p1=new?PCB;
p1->next=NULL;
cout<<“請依次輸入第“< cin>>p1->name>>p1->ta>>p1->ts;
p1->tm=p1->ts;
p1->rn=1;
p2->next=p1;
}
return?head;
}

void?sort(PCB?*head)//將進程按到達的先后順序排列
{
PCB?*p*q*r*s;
if(head->next!=NULL)
{
p=head->next->next;
head->next->next=NULL;
}
while(p)
{
q=p;
p=p->next;
r=head;
s=head->next;
while(s&&s->ta<=q->ta)
{
r=s;
s=s->next;
}
r->next=q;
q->next=s;
}
}

void?del(PCB?*?p)//刪除p的下一個節點
{
PCB?*tmp;
tmp=p->next;
p->next=tmp->next;
free(tmp);
}

int?getCount(PCB?*headint?time)//察看在time之前到達但未移動到運行隊列的進程數量
{
int?count=0;
PCB?*s*t;
s=head;
t=s->next;
while(t!=NULL&&t->ta<=time)
{
???s=t;
???t=t->next;?
???count++;//count記錄當前時刻到達的進程數
}
return?count;
}

void?FCFS(PCB?*head)//先來先服務算法
{
int?i=0j=0;
total=0;
weight=0;
sort(head);
int?time=0count;
PCB?*p*q;
while(head->next!=NULL)
{
count=getCount(headtime);
if(count==0)time++;
else
{
p=head;
q=p->next;
cout<<“******************************************************“< cout<<“進程名:“<name< pname[i]=q->name;
i++;
cout<<“到達時間:“<ta< q->tb=time;
cout<<“進程開始運行時間:“<tb< time=q->tb+q->ts;
cout<<“進程運行結束時間:“< q->totalTime=time-q->ta;
cout<<“周轉時間:“<totalTime< total+=q->totalTime;
q->weightTotalTime=q->totalTime/(double)q->ts;
weight+=q->weightTotalTime;
cout<<“帶權周轉時間:“<weightTotalTime< cou

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????6165??2010-01-25?21:32??fcfs&sjf.cpp

-----------?---------??----------?-----??----

?????????????????6165????????????????????1


評論

共有 條評論