Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Icdt 88 2nd International Conference On Database Theory Bruges Belgium August 31 September 2 1988 Proceedings Lncs 326

Authors: Marc Gyssens ,Jan Paredaens ,Dirk Van Gucht

1st Edition

3540501711, 978-3540501718

More Books

Students also viewed these Databases questions

Question

Identify the depressants, and describe their effects.

Answered: 1 week ago