Skip to content

Commit d68ff9d

Browse files
author
=
committed
Added interval partitioning code
1 parent 74da732 commit d68ff9d

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

greedy/a.out

8 Bytes
Binary file not shown.

greedy/intervalpartitioning.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int n,i,j,temp;
5+
printf("Enter the number of activities: ");
6+
scanf("%d",&n);
7+
int pnum[n],start[n],end[n],result,hall;
8+
for(i=0;i<n;i++)
9+
{
10+
printf("Details of process number %d\n",i+1);
11+
printf("Process number: ");
12+
scanf("%d",&pnum[i]);
13+
printf("Start time: ");
14+
scanf("%d",&start[i]);
15+
printf("End time: ");
16+
scanf("%d",&end[i]);
17+
}
18+
for(i=0;i<n;i++)
19+
{
20+
for(j=i;j<n;j++)
21+
{
22+
if(start[i]>start[j])
23+
{
24+
temp=start[i];
25+
start[i]=start[j];
26+
start[j]=temp;
27+
temp=end[i];
28+
end[i]=end[j];
29+
end[j]=temp;
30+
temp=pnum[i];
31+
pnum[i]=pnum[j];
32+
pnum[j]=temp;
33+
}
34+
}
35+
}
36+
printf("Sorted process on basis of start time are\n");
37+
printf("Process number start time End time\n");
38+
for(i=0;i<n;i++)
39+
{
40+
printf("%d %d %d\n",pnum[i],start[i],end[i]);
41+
}
42+
i=1;
43+
j=0;
44+
result=1;
45+
hall=1;
46+
while (i<n && j<n)
47+
{
48+
if(start[i]<end[j])
49+
{
50+
hall++;
51+
i++;
52+
if(result<hall)
53+
{
54+
result=hall;
55+
}
56+
}
57+
else
58+
{
59+
hall--;
60+
j++;
61+
}
62+
}
63+
printf("Number of halls needed are: %d\n",result);
64+
return 0;
65+
}

0 commit comments

Comments
 (0)