Question: c++ need help with partition function. may not change any of the code in main #include using namespace std; // You may not change my

c++ need help with partition function. may not change any of the code in main

#include using namespace std;

// You may not change my code in any manner. 0 pts if you do. // Simply add your code for **

//---------------------------------------- //CS311 HW2P2 Partition //Name: //Compiler: g++ //-----------------------------------------

// partitions the array a into smaller than pivot and others. // f is the beginning of the section to be partitioned // r is the end of the section to be partitioned // return the first slot of the Large section int partition(int pivot, int a[], int f, int r) { int left = f; // pointer from the left int right = r; // pointer from the right

// loop for finding out of place pairs and swap them // ** until the left and right cross // if left OK, move left // if right OK, move right // if both are bad, swap

// return the partition point where // those smaller than pivot are before what is returned // ** there is a special cases and a regular case }

int main() { int x; // number of elements int nums[10]; cout << "How many elements? (must be less than 10) "; cin >> x; cout << "Enter elements one per line.." << endl; for (int i = 0; i < x; i++)

{ cin >> nums[i]; }

// the pivot is always the first element cout << "Ok the pivot is " << nums[0] << endl;

int part = partition(nums[0], nums, 0, x-1);

cout << "Results..." << endl; // display up to the partition without endl for (int i = 0; i < part; i++) cout << num[i];

cout << "|"; // display from the partition on.. without endl for (int i = part; i < x; i++) cout << num[i];

cout << endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!