From 5cc6e65924ca2e0e17e3baca6bd37c5ea130d796 Mon Sep 17 00:00:00 2001 From: VIKRAM MOHANTY <53655438+vikram-12@users.noreply.github.com> Date: Thu, 15 Oct 2020 18:29:51 +0530 Subject: [PATCH] activity_selection_problem_greedy_method activity selection problem using greedy method . written in c++ --- activity_selection_problem.cpp | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 activity_selection_problem.cpp diff --git a/activity_selection_problem.cpp b/activity_selection_problem.cpp new file mode 100644 index 0000000..378b9c8 --- /dev/null +++ b/activity_selection_problem.cpp @@ -0,0 +1,53 @@ +#include + +using namespace std; +#define N 6 + +struct Activity +{ + int start, finish; +}; + + +bool Sort_activity(Activity s1, Activity s2) +{ + return (s1.finish< s2.finish); +} + + +void print_Max_Activities(Activity arr[], int n) +{ + + sort(arr, arr+n, Sort_activity); + + cout<< "Following activities are selected \n"; + + + int i = 0; + cout<< "(" <= arr[i].finish) + { + cout<< "(" <>arr[i].start>>arr[i].finish; + } + + print_Max_Activities(arr, N); + return 0; +}