流水作业调度完整代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//流水作业调度.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*);
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 (i nt n = m+1; n < b; n++) if (wo[n].a < wo[m].a) {
{
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;
} void Order(JOB* temp)
{
cout << "加工顺序为:";
for (int a = 0; a < NUM; a++)
{
cout<<setw(3)<<temp[a].i ndex;
}源自文库
cout << "\n\n";
}
{
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];
{
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)
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;
}
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++)
{
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 )
相关文档
最新文档