JAVA PROGRAM SELECTION SORT USING RECURSION

posted by .

JAVA PROGRAM Details:
I'm having a trouble with the print lines, i'm not sure where to start but i think I got the rest down correctly. Please if there is a mistake in this program, let me know or correct my current program below, this program should be compiled in JGRASP OR BLUEJ please try it to compile yourself too.

Thanksthe sort() method calls sortSublist(0,length-1) * * Write a DRIVER with a main() method to test your sorting algorithm. * It should do the following: * * 1. Generate a list of 50 random integers. * 2. Print out the unsorted list (with 5 integers per line). * 3. Sort the list. * 4. Print out the sorted list. * ***************************************************************************/ class SortableIntegerList { private int maxLength, // The length of the array length; // The length of the list (length <= maxLength) private int[] a; // An array with the integers in the list public SortableIntegerList (int mxLen) // Creates an empty list with maximum length mxLen { maxLength = mxLen; length = 0; a = new int[maxLength]; }




Optional Information:
Level: 2nd; Subject: Computer Science/Data Structure and Algorithm

Already Tried:
class SortableIntegerList
{
private int maxLength, // The length of the array
length; // The length of the list (length <= maxLength)
private int[] a; // An array with the integers in the list

public SortableIntegerList (int mxLen)
// Creates an empty list with maximum length mxLen
{
maxLength = mxLen;
length = 0;
a = new int[maxLength];
}

public void append (int value)
// Append the value to the end of the list
{
a[length] = value;
length++;
}

public void sort()
// Sort the list from smallest to largest
{
sortSublist(0,length-1);
}

private void sortSublist(int startIndex, int endIndex)
// Sort the sublist a[startIndex]...a[endIndex]
// IMPORTANT: This method must be recursive!
{
// YOUR CODE GOES HERE!
if ( endIndex >= startIndex.length -1 )
return;
int minIndex = endIndex;
for ( int index = endIndex + 1; index < startIndex.length; index++ )
{
if (startIndex[index] < startIndex[minIndex] )
minIndex = index;
}
int temp = startIndex[endIndex];
startIndex[endIndex] = startIndex[minIndex];
startIndex[minIndex] = temp;
sortSublist(startIndex, endIndex +1);
}

}

public void printList ()
/* Prints the values in the list to standard output with
five values per line, properly aligned in columns
*/
{
// YOUR CODE GOES HERE!


}

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. Java

    I am trying to write an algorithm for my JAVA class and am having some issues....if I were to post my program is there anyone on here that could help me figure out what I am doing wrong?
  2. programming

    I am having trouble writing this program for java. can anybody help write a program that prints the letter X composed of asterisk.
  3. JAVA

    simple java program to retrive data from oracle database between specific dates.. Please somebody help na?
  4. Java Programming

    I'm new to Java and I'm not sure how to write the source code for this problem I got in class... Write a java program using the while and if statement that will accept ten student grades and that will display the sum of the grades, …
  5. java programming

    write a java program using arrays function for hotel bill calculation?
  6. JAVA PROGRAMMING

    Create a java program that will calculate the current grade in a classroom. The program should ask for 5 grades as well as total point value per grade available.
  7. java.please help

    Write a Java program that prompts the user for a string. If the string entered by the user does not start with Hello and does not end with a digit, print incorrect and re-prompt the user. Otherwise, print Thank you.
  8. java programming

    Create a java program that will calculate the current grade in a classroom. The program should ask for 5 grades as well as total point value per grade available.
  9. java program

    Create a program that will print the student’s letter grade given the following specifications : 90 – 100 = A 80 – 89 = B 70 – 79 = C 60 – 69 = D below 60 = F
  10. Java programming

    Need help not sure how do this Do an analysis of the following program: Write a program to input the dimension of a cylinder, and print the surface area and volume.

More Similar Questions