# Iterative quick sort using median of three values

• September 30th, 2012, 09:26 PM
omfgz
Iterative quick sort using median of three values
I'm stuck on this question for a while now and can't think of anything anymore so i need someones help to point me to right direction.

Question is :

Quote:

Create A modified recursive quick sort method that uses the median-of-three method to choose the pivot. Also, the base cases for this modified method are lists of 10 elements or less. Your modified method should sort a list of 10 elements or less directly (i.e., with no recursion) using an iterative algorithm of your choosing.
After doing some research i figured out what is exactly median of three alg using quick sort and wrote the following code :

Code :

``` public static void mQuickSort(int numbers[],int low,int high) { if (high <= 10){   int mid,replace,lowCount,highCount;     lowCount = low; mid = (high + low) /2; highCount = mid + 1; if (numbers[mid] < numbers[low]) { replace = numbers[low]; numbers[low] = numbers[mid]; numbers[mid] = replace; } if (numbers[high] < numbers[low]) { replace = numbers[low]; numbers[low] = numbers[high]; numbers[high] = replace; } if (numbers[mid] < numbers[low]) { replace = numbers[mid]; numbers[mid] = numbers[high]; numbers[high] = replace; } replace = numbers[mid]; numbers[mid] = numbers[high-1]; numbers[high-1] = replace;     }```

:confused: I have no idea what to do next. I have created code for quick sort using recursion and it seems to be working fine but im not totally sure what is this question ask me for. Could some one please point me to right direction. Thank you
• September 30th, 2012, 09:59 PM
macko
Re: Iterative quick sort using median of three values
break it down to points. do a search on each part of the question you need to further understand the meaning of.

"usually you would create an algorithm before developing a program or in this case a sorting routine."

Once you have an algorithm or pseudocode then you can further understand and complete this task.. good luck