using namespace std;
int MinPlatform(float arr[], float dep[], int n) // Find minimum number of platforms needed
{
// Sort both the arrival and departure arrays
sort(arr, arr+n);
sort(dep, dep+n);
// print both the arrival and departure arrays after sorting
cout<"\n sorted="" arrival="" array="" is="" :="">"\n>
for(int i=0;i<>
cout<><">">
cout<"\n sorted="" departure="" array="" is="" :="">"\n>
for(int i=0;i<>
cout<><">">
// platform_counter indicates number of platforms needed at a time
int platform_counter = 1, result = 1;
int i = 1, j = 0;
// To process all train events in sorted order
while (i < n="" &&="" j=""><>
{
// If train is scheduled to arrive next , we increase the counter by 1 and update platform_counter
if (arr[i] <>
{
platform_counter++;
i++;
// Update the value of result if Required
if (platform_counter > result)
result = platform_counter;
}
// If the train is scheduled to depart next, we decrease the counter by 1 and update platform_counter
else
{
platform_counter--;
j++;
}
}
return result;
}
// Main program
int main()
{
float arrival[] = {2.00 , 2.10 , 3.00 , 3.20 , 3.50 , 5.00};
float departure[] = {2.30 , 3.40 , 3.20 , 4.30 , 4.00 , 5.20};
int n = sizeof(arrival)/sizeof(arrival[0]);
// print both the given arrival and departure arrays
cout<"\n given="" arrival="" array="" is="" :="">"\n>
for(int i=0;i<>
cout<><">">
cout<"\n given="" departure="" array="" is="" :="">"\n>
for(int i=0;i<>
cout<><">">
// print the result
cout < "\n minimum number of platforms required = "
<< minplatform(arrival, departure, n);
return 0;
}
"\n="" minimum="" number="" of="" platforms="" required=""> "\n minimum number of platforms required = "
<< minplatform(arrival, departure, n);
return 0;
}