Question: I need help with a QuickSort medianOf3 hoarePartition C++ program. This is what I have so far: #ifndef QUICKSORT_H #define QUICKSORT_H #include using std::swap; //note

I need help with a QuickSort medianOf3 hoarePartition C++ program. This is what I have so far:

#ifndef QUICKSORT_H #define QUICKSORT_H

#include

using std::swap;

//note returns INDEX of median template inline int medianOf3(T A[], int l, int r){ //this is overcommented... also, try and avoid using pointers T* a = A + l;//array name is just pointer to 1st (0 index) elem., + l shifts l*(T size) T* b = A + l + (r-l)/2;//middle item... int division rounds down T* c = A + r;

//when a is a pointer, *a is the dereference operator (gives value a points to) T* m; if(*a < *b){ if(*b < *c) m=b; else if(*c < *a) m=a; else m=c; } else{ //b <=a if(*a < *c) m=a; else if(*c < *b) m=b; else m=c; } return m-A; //m-A is the number of elements from A[0]

//remember: l and r are INLCUSIVE (just like Lomuto) template Can someone lead me in the right direction. I need to use the medianOf3 and implement it in hoarePartition and finish the quicksort. int hoarePartition(T A[], int l, int r){ T x = A[l], i = l-1, j = r; while (1) { do j--; while (A[j] > x); do i++; while (A[i] < x);

if (i < j) swap(A[i],A[j]); else return 0; }

template void quicksort(T A[], int l, int r){

}

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!