-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJobSequencing.cpp
69 lines (64 loc) · 1.4 KB
/
JobSequencing.cpp
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
61
62
63
64
65
66
67
68
69
#include<bits/stdc++.h>
using namespace std;
class Job{
public:
char JobID[5];
int profit;
int deadline;
public:
Job(){
}
};
bool compare(Job a,Job b)
{
return a.profit>b.profit;
}
bool comparison(Job a ,Job b)
{
return a.deadline>b.deadline;
}
void Jobsequencing(Job array[],int n)
{
char result[n];
sort(array,array+n,compare);
int slot[n];
for(int i=0;i<n;i++)
{
slot[i]=0;
for(int j=min(n,array[i].deadline)-1;j>=0;j--)
{
if(slot[j]==0){
result[j]=i;
slot[j]=j+1;
break;
}
}
}
cout<<"JOB ID"<<"\t\t"<<"SLOT"<<"\t\t"<<"PROFIT"<<endl;
for (int i = 0; i <n; i++)
{
if (slot[i])
{
cout<<array[result[i]].JobID<<"\t\t"<<slot[i]<<"\t\t"<<array[result[i]].profit<<endl;
}
}
}
int main()
{
int n;
cout<<"Enter Number of Jobs:"<<endl;
cin>>n;
Job array[n];
for (int i=0;i<n;i++)
{
cout<<"ENTER DETAILS FOR JOB "<<i+1<<endl;
cout<<"ENTER JOB ID:"<<endl;
cin>>array[i].JobID;
cout<<"ENTER PROFIT:"<<endl;
cin>>array[i].profit;
cout<<"ENTER DEADLINE OF JOB:"<<endl;
cin>>array[i].deadline;
}
Jobsequencing(array,n);
return 0;
}