Respuesta :
Answer:
Program;
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> order = {1, 2, 3, 4, 5}; // initial job order
vector<pair<float, vector<int> > > data; // each pair is {average waiting time, jobs order}
int c = 0;
do {
// calculate average waiting time for the order
float avg_wait = 0;
for(int i = 0; i < order.size() - 1; ++i) {
avg_wait += order[i];
}
avg_wait /= 5;
data.push_back(make_pair(avg_wait, order));
} while(next_permutation(order.begin(), order.end()));
// sort according to average wait time
sort(data.begin(), data.end());
// display the result
cout << "avg_wait_time\tpermutation\n\n";
for(int i = 0; i < 120; ++i) {
cout << data[i].first << "\t\t";
for(int j = 0; j < 5; ++j) {
cout << data[i].second[j] << " ";
}
cout << endl;
}
Explanation:
See attachment for code screenshot


