-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjobsequencingproblem.cpp
More file actions
60 lines (51 loc) · 1 KB
/
jobsequencingproblem.cpp
File metadata and controls
60 lines (51 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
struct Job
{
char id;
int dead;
int profit;
};
bool comparision(Job a,Job b)
{
return(a.profit>b.profit);
}
void printJobScheduling(Job arr[],int n)
{
sort(arr,arr+n,comparision);
int result[n];
bool slot[n];
for(int i=0;i<n;i++)
{
slot[i] = false;
}
for(int i=0;i<n;i++)
{
for(int j=min(n,arr[i].dead)-1;j>=0;j--)
{
if(slot[j]==false)
{
result[j] = i;
slot[j] = true;
break;
}
}
}
for(int i=0;i<n;i++)
{
if(slot[i])
{
cout<<arr[result[i]].id<<" ";
}
}
}
int main()
{
Job arr[] = { {'a', 2, 100}, {'b', 1, 19}, {'c', 2, 27},
{'d', 1, 25}, {'e', 3, 15}};
int n = sizeof(arr)/sizeof(arr[0]);
cout << "Following is maximum profit sequence of jobs \n";
// Function call
printJobScheduling(arr, n);
return 0;
}