IN C Implement the pseudocode of a and b the below Your prog

IN C++

Implement the pseudocode of a and b the below. Your program will first ask the user to input the number of activities, next it will ask the user to input a group of starting times, then a group of finishing times. The output will be a subset of maximum number of compatible activities. Deliverable: A complete program that can be compiled and run, and attach a screen shot of your running program. Recursive-Activity-Selector (s, f, i, j) m leftarrow i+1 while m

Solution

#include <iostream>
#include <set>
using namespace std;

set<int> recursive_activity_selector( int* start_times, int* finish_times, int i, int j )
{
   int m = i + 1;
   while( m < j && start_times[m] < finish_times[i] ){
       m = m + 1;
   }
   set<int> result;
   if( m < j ){
       result = recursive_activity_selector( start_times, finish_times, m, j );
       result.insert( m );
   }
   return result;
}

set<int> greedy_activity_selector( int* start_times, int* finish_times, int n )
{
   set<int> result;
   result.insert(0);
   int i = 0;
   for( int m = 1; m < n; m++ ){
       if( start_times[m] >= finish_times[i] ){
           result.insert( m );
           i = m;
       }
   }
   return result;
}

int main(){
   int numberOfActivities;
   int* start_times;
   int* end_times;

   cout << \"Enter the number of activities: \";
   cin >> numberOfActivities;
   start_times = new int[numberOfActivities];
   end_times = new int[numberOfActivities];
   cout << \"Enter starting times for \" << numberOfActivities << \" activities\" << endl;
   for(int i = 0; i < numberOfActivities; i++){
       cin >> start_times[i];
   }
   cout << \"Enter finishing times for \" << numberOfActivities << \" activities\" << endl;
   for(int i = 0; i < numberOfActivities; i++){
       cin >> end_times[i];
   }

   set<int> result = recursive_activity_selector( start_times, end_times, 0, numberOfActivities );
   set<int> result2 = recursive_activity_selector( start_times, end_times, 0, numberOfActivities );

   return 0;
}

IN C++ Implement the pseudocode of a and b the below. Your program will first ask the user to input the number of activities, next it will ask the user to input
IN C++ Implement the pseudocode of a and b the below. Your program will first ask the user to input the number of activities, next it will ask the user to input

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site