Question: Warning C4715 'partition': not all control paths return a value Project2 I keep getting this error and my program stops after the merge sort. Please

Warning C4715 'partition': not all control paths return a value Project2

I keep getting this error and my program stops after the merge sort. Please help! I believe the problem is with my partition function

//************************************************************************* // QUICKSORT IMPLEMENTATION: // //*************************************************************************

size_t partition(int data[], size_t n, size_t& pivot_index) { // Check that n not equal 0 if (n > 1) {

int pivot = data[0]; int too_big_index = 1; // Index of first item after pivot int too_small_index = n - 1; // Index of last item

// Increment too_big_index while <= too_small_index while (too_big_index <= too_small_index) { // Increment to_big_index while < n and <= pivot while ((too_big_index < data[n]) && (data[too_big_index] <= pivot)) { too_big_index++; } // Decrement too_small_index while data[too_small_index] > pivot while (data[too_small_index] > pivot) { too_small_index--; } if (too_big_index < too_small_index) { int temp = data[too_big_index]; // Temporary Variable to hold data[too_big_index] // // Swap [too_big_index] and [too_small_index] data[too_big_index] = data[too_small_index]; data[too_small_index] = temp; }

} pivot_index = too_small_index; data[0] = data[pivot_index]; data[pivot_index] = pivot; return pivot_index; }

}

void quicksort(int data[], size_t n) { size_t pivot_index; // Array index for the pivot element size_t n1; // Number of elements before the pivot element size_t n2; // Number of elements after the pivot element

if (n > 1) { // Partition the array, and set the pivot index. partition(data, n, pivot_index);

// Compute the sizes of the subarrays. n1 = pivot_index; n2 = n - n1 - 1;

// Recursive calls will now sort the subarrays. quicksort(data, n1); quicksort((data + pivot_index + 1), n2); } }

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!