流水作业调度完整代码
} void Order(JOB* temp)
{
cout << "加工顺序为:";
for (int a = 0; a < NUM; a++)
{
cout<<setw(3)<<temp[a].i ndex;
}
cout << "\n\n";
}
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) {
JOB job = rk[m]; rk[m] = rk[ n]; rk[n] = job;
{
int j, k;
j = temp[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;
else
k = j+temp[a].b;
}
cout << "花费的时间是:"<< k<<e ndl;
{
cout << "请输入要加工的工件数量:";
cin>>NUM;
JOB* work=new JOB[NUM]; cout << "请输入数据:\n";
In put(work);
Sort(work);
Order(work);
Output(work);
delete work;
return 0;
}
void Sort( JOB* temp )
}
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 In put( JOB* temp )
{
for (int a = 0; a < NUM; a++)
//流水作业调度.cpp:定义控制台应用程序的入口点。
#i nclude"stdafx.h"
#in elude <iostream>
#in clude<ioma nip>
using n amespace std;
static int NUM;
struct JOB
{
int a;// 1st
int b;// 2nd
bool type;//mark a>b or b>a int index;//save initial subscript
};
void Sort( JOB* );
void In put( JOB* );
void Output(JOB*); argc, _TCHAR* argv[])
{
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 temp[a].i ndex = a+1;
void Output(JOB* temp)
{
int b =0, c = 0;
for (int a = 0; a < NUM; a++)
{
if (temp[a].type == 0)//co unt
b++;〃num of type 0
else
c++;// num of type 1
}
JOB* wo = new JOB[b];
JOB* rk = new JOB[c];
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 (i nt n = m+1; n < b; n++) if (wo[n].a < wo[m].a) {