Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Iterative quick sort using median of three values

1. ## 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 :

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 :

```  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;

}```

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

2. ## 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