-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathJobSequencing.c
More file actions
58 lines (55 loc) · 1.43 KB
/
JobSequencing.c
File metadata and controls
58 lines (55 loc) · 1.43 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
// Job Sequencing
#include <stdio.h>
int main(){
int num,temp,slots,c=0,tp=0,profit[20],deadline[20],slot[10]={0},job[20];
printf("Enter the number of jobs : ");
scanf("%d",&num);
for(int i=1;i<=num;i++){
printf("Enter profit %d and its deadline : ",i);
scanf("%d%d",&profit[i],&deadline[i]);
job[i]=i;
}
for(int i=1;i<=num-1;i++){
for(int j=i+1;j<=num;j++){
if(profit[i]<profit[j]){
temp=job[j];
job[j]=job[i];
job[i]=temp;
temp=profit[j];
profit[j]=profit[i];
profit[i]=temp;
temp=deadline[j];
deadline[j]=deadline[i];
deadline[i]=temp;
}
}
}
slots=0;
for(int i=1;i<=num;i++){
if(slots<deadline[i]){
slots=deadline[i];
}
}
for(int i=1;i<=num;i++){
printf("Job%d : Profit : %d Deadline : %d\n",job[i],profit[i],deadline[i]);
}
for(int i=1;i<=num;i++){
for(int j=deadline[i];j>=1;j--){
if(slot[j]==0){
slot[j]=job[i];
c++;
tp=tp+profit[i];
break;
}
}
if(c==slots)
break;
}
printf("The job sequence is : ");
for(int i=1;i<=slots;i++)
{
if(slot[i]!=0)
printf("--->%d",slot[i]);
}
printf("\nMaximum profit : %d",tp);
}