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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Iterative quick sort using median of three values

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    1
    My Mood
    Cheerful
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post 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. #2
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default 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

Similar Threads

  1. Java Quick Sort Optimization
    By javaNewb37 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 4th, 2011, 07:32 AM
  2. recursive program to find median
    By TeamRival in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 26th, 2011, 10:40 PM
  3. [SOLVED] Quick JTable Column Sort Question
    By aussiemcgr in forum Java Theory & Questions
    Replies: 1
    Last Post: October 15th, 2010, 04:35 PM
  4. Iterative Help
    By Jnoobs in forum Java Theory & Questions
    Replies: 12
    Last Post: October 6th, 2010, 07:40 PM
  5. Arrays.sort or iterative search?
    By igniteflow in forum Collections and Generics
    Replies: 1
    Last Post: September 16th, 2009, 02:07 AM