当前位置:文档之家› 流水作业调度完整代码

流水作业调度完整代码

{
int b =0, c = 0;
for (int a = 0; a < NUM; a++)
{
if (temp[a].type == 0)//count
b++;// num of type 0
else
c++;// num of type 1
}
JOB* wo = new JOB[b];
JOB* rk = new JOB[c];
{
for (int a = 0; a < NUM; a++)
{
cout << a + 1 << ":\n A:";
cin >> temp[a].a;
cout << " B:";
cin >> temp[a].b;
temp[a].type = temp[a].a > temp[a].b ? 1 : 0;//a>b 1 or 0
{
cout << "请输入要加工的工件数量:";
cin >> NUM;
JOB* work=new JOB[NUM];
cout << "请输入数据:\n";
Input(work);
Sort(work);
Order(work);
Output(work);
delete work;
return 0;
}
void Sort( JOB* temp )
{
JOB job = rk[m];
rk[m] = rk[n];
rk[n] = job;
}
for (int m = 0; m < b; m++)
temp[m] = wo[m];
for (int m = b ,n=0; m < NUM; m++,n++)
temp[m] = rk[n];
}
void Input( JOB* temp )
else
k = j + temp[a].b;
}
cout << "花费的时间是:" << k<<endl;
}
void Order(JOB* temp)
{
cout << "加工顺序为:";
for (int a = 0; a < NUM; a++)
{
cout<<setw(3)<<temp[a].index;
//流水作业调度.cpp :定义控制台应用程序的入口点。
#include"stdafx.h"
#include <iostream>
#include<iomanip>
using namespace std;
static int NUM;
struct JOB
{
int a;// 1st
int b;// 2nd
}
cout << "\n\n";
}
bool type;//mark a>b or b>a
int index;//save initial subscript
};
void Sort( JOB* );
void Input( JOB* );
void Output(JOB*);
void Order(JOB*);
int _tmain(int argc, _TCHAR* argv[])
b = c = 0;
for (int a = 0; a < NUM; a++)//divide
{
if (temp[a].type == 0)
wo[b++] = temp[a];
else
rk[c++] = temp[a];
}
//sort wo
for (int m = 0; m < b; m++)
for (int n = m + 1; n < b; n++)
temp[a].index = a + 1;
}
}
void Output(JOB* temp)
{
int j, k;
j = [0].a;
k = j + temp[0].b;
for (int a = 1; a < NUM; a++)
{
j += temp[a].a;
if (j < k)
k = k + temp[a].b;
if (wo[n].a < wo[m].a)
{
JOB job=wo[m];
wo[m] = wo[n];
wo[n] = job;
}
//sort rk
for (int m = 0; m < c; m++)
for (int n = m + 1; n < c; n++)
if (rk[n].b > rk[m].b)
相关主题