How to sort calling method from other Java program?

Jay Mozart

New member
The code below is the method to sort. I need to call sorting method to sort the integers on my main program. Where and what type of code would I write to make it sort?

I tried like Sorting.selectionSort(), Sorting.selectionSort(Comparable[] array)but those didn't work.

This is the outlook of my main method:

public class Test {
public static void main(String []args) {
}
}

class People implements Comparable {
public People(String x, Integer y) {
}
public String toString() {
}
public int getAge() {
}
public int compareTo(Object object) {
}
}

---

import java.lang.Comparable;
public class Sorting {

/*Set this to "false" to turn off display*/
public static Boolean display = true;

/**main method starts the program
* @param args must be Integers only */
public static void main(String args[]) {
// selectionSort
Integer[] array = Sorting.arrayCopy(args);
System.out.println("selectionSort");
Sorting.print(array);
Sorting.selectionSort(array);
System.out.println();


/**selection sort
* @param array is an array of Comparable objects
*/
public static void selectionSort(Comparable[] array) {
Sorting.selectionSort(array, 0, array.length-1);
}

/**selection sort
* @param array is an array of Comparable objects
* @param start is the first element in the array
* @param end is the last element in the array */
public static void selectionSort(Comparable[] array, int start, int end) {
// loop from first element to 2nd to last element
for (int i = start; i < end; i++) {
// find index of smallest element
int smallest = findSmallest(array, i, end);
// swap smallest with current position in array
Comparable temp = array[smallest];
array[smallest] = array;
array = temp;
//print the array to show each step
if(Sorting.display){
Sorting.print(array, start, end);
}
}
}
 
Back
Top