Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5.7 Partition Vector Into Three Sections You are to sort an array that consists only of 0, 1, 2. The strategy behind the optimal solution
5.7 Partition Vector Into Three Sections You are to sort an array that consists only of 0, 1, 2. The strategy behind the optimal solution is based on Lomuto's partition scheme for Quicksort. Your solution must be in one pass and in-place. One pass means traversing the vector only once. Do not use a second vector, or a two pass algorithm. Do not use the algorithm library Examples Input of 2010112 will result in 0011122 Input Do not read in input! There will be no input read in anymore. Going forward use the hard-coded input on the template and ensure the program works. There will be one compare output test based on the hard-coded input. The rest of the tests will be unit tests. Output Print the results from your function with a space between each integer LAB ACTIVITY 5.7.1: Partition Vector Into Three Sections 0/4 Downloadable files main.cpp Download main.cpp Load default template... Dovo 1 #include 2 #include 3 void threeWayPartition std::vector & vec { /* Less hints were requested, however a few hints are needed. 1) Write the problem out on paper. The partition will be tricky and there are certain edge cases. 2) Think of these cases against your solution [2 1 0], [1 2 0], [2, 0, 1] YOUR SOLUTION MUST FOLLOW THE DIRECTIONS, THIS PROBLEM IS TRIVIAL IF YOU ALLOW TWO PASSES. ONLY ONE PASS AND IN-PLACE IS ALLOWED. */ 10 } 11 int main() { // Went ahead and provided this for you, just concentrate on the function std::vector test {2, 2, 0, 0, 1, 1, 0, 1}; threeWayPartition test); for(int i : test ) { std::cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started