Skip to content

Commit eb3e130

Browse files
author
chh
committed
activity selection
1 parent 0ae30f7 commit eb3e130

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

greedy_algorithms/activity_selection.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,30 @@ static void tests() {
4242
std::vector<int> finish = {2, 4, 6, 7, 9, 9};
4343

4444
std::vector<int> ans = getMaxActivities(start, finish, start.size());
45-
std::vector<int> activities = {0, 1, 6, 4};
45+
// activity 0, 1, 3, 4 are selected since their start time is greater than the end time of the previous activity
46+
std::vector<int> activities = {0, 1, 3, 4};
4647

4748
for(int i = 0 ; i < activities.size(); i++){
4849
uint64_t activityNumber = ans[i];
4950
assert(activityNumber == activities[i]);
5051
}
52+
std::vector<int> start2 = {10, 12, 20};
53+
std::vector<int> finish2 = {20, 25, 30};
54+
55+
std::vector<int> ans2 = getMaxActivities(start2, finish2, start2.size());
56+
// only the first activity is chosen, others dont fulfill the criteria
57+
std::vector<int> activities2 = {0};
58+
59+
for(int i = 0 ; i < activities2.size(); i++){
60+
uint64_t activityNumber = ans2[i];
61+
assert(activityNumber == activities2[i]);
62+
}
63+
5164
}
5265

5366
// Driver code
5467
int main()
5568
{
56-
//tests();
57-
std::vector<int> start = {1, 3, 0, 5, 8, 5};
58-
std::vector<int> finish = {2, 4, 6, 7, 9, 9};
59-
// Function call
60-
std::vector<int> ans = getMaxActivities(start, finish, start.size());
61-
std::cout << "Following activities are selected" << "\n";
62-
for(int x: ans) {
63-
std::cout << x <<", ";
64-
}
69+
tests();
6570
return 0;
6671
}

0 commit comments

Comments
 (0)