-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActivitySelection.c
50 lines (35 loc) · 1.1 KB
/
ActivitySelection.c
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
#include<stdlib.h>
int main() {
int start[]={0,5,3,1,8,5};
int finish[]={6,7,4,2,9,9};
int n=(int)sizeof(start)/sizeof(start[0]);
int selects[n];
int selectf[n];
int temp,tempi;
for(int i=0;i<n;i++){
for(int j=1;j<(n-i);j++){
if(finish[j-1]>finish[j]){
temp=finish[j-1];
finish[j-1]=finish[j];
finish[j]=temp;
tempi= start[j-1];
start[j-1]=start[j];
start[j]=tempi;
}
}
}
printf("Sorted Activities:\n");
for(int i=0;i<n;i++){
printf("%d %d\n",start[i],finish[i]);
}
printf("Maximum Set of Activities:\n");
printf("[Index: Start Finish]\n");
int j=0;
printf("0 : %d %d\n",start[0],finish[0]);
for(int i=1;i<n;i++){
if(start[i]>=finish[j]){
j=i;
printf("%d : %d %d\n",i,start[i],finish[i]);
}
}
}