当前位置:首页 > 读后感 > 先来先服务算法|先来先服务算法例题
 

先来先服务算法|先来先服务算法例题

发布时间:2019-07-18 09:36:26 影响了:

先来先服务算法

#include

#include

#include

using namespace std;

#define MAX 10

char process[MAX]=""; //进程标识

int arrivetime[MAX];//达到时间

int servicetime[MAX];//服务时间

int finishtime[MAX]; //完成时间

int turnovertime[MAX];//周转时间

double avgturnovertime; //平均周转时间

double powertime[MAX]; //带权周转时间

double avgpowertime; //平均带权周转时间

int init();

void FCFS();

void output();

void showsingle(int* arr,int len);

//初始化,并返回进程数

int init()

{

cout

while(i

{

cin.get(process[i]);

if(process[i]==" " || process[i]=="/t")

{

continue;

}

if(process[i]=="q" || process[i]=="/n")

{

process[i]="/0";

peak;

}

i++;

}

int len=strlen(process);

cout

for(int ix=0; ix

{

cin >> arrivetime[ix];

}

cout

for(ix=0; ix

{

cin >> servicetime[ix];

}

return len;

}

void FCFS(int len)

{

//完成时间的计算

for(int ix=0; ix

{

finishtime[ix]=accumulate(servicetime,servicetime+ix+1,0);

}

//周转时间计算

for(ix=0; ix

{

turnovertime[ix]=finishtime[ix]-arrivetime[ix];

}

avgturnovertime=accumulate(turnovertime,turnovertime+len,0)*1.0/len;

//带权周转时间计算

for(ix=0; ix

{

powertime[ix]=turnovertime[ix]*1.0/servicetime[ix];

}

//平均带权周转时间

double tmptotal=0.0;

for(ix=0; ix

{

tmptotal+=powertime[ix];

}

avgpowertime=tmptotal/len;

}

void output()

{

cout

cout

int len=strlen(process);

//显示进程序列

for(int ix=0; ix

{

cout

}

cout

//显示到达时间序列

showsingle(arrivetime,len);

//显示服务时间序列

showsingle(servicetime,len);

cout

//显示完成时间序列

showsingle(finishtime,len);

//显示周转时间序列

showsingle(turnovertime,len);

cout

//显示带权周转时间序列

for(ix=0; ix

{

cout

}

cout

cout

cout

}

//对int 类型的数组进行格式化输出

void showsingle(int* arr,int len)

{

for(int ix=0; ix

{

cout

}

cout

}

int main()

{

cout

int len = init();

FCFS(len);

output();

system("PAUSE");

return 0;

}

猜你想看
相关文章

Copyright © 2008 - 2022 版权所有 职场范文网

工业和信息化部 备案号:沪ICP备18009755号-3