-1

i have this method that i got from a website about selection sort that i need to check how it works :

public static void selectionSort(int[] data, int low, int high) {
    if (low < high) {
    swap(data, low, findMinIndex(data, low));
    selectionSort(data, low + 1, high);

    }


public static void swap(int[] array, int index1, int index2) {
    int tmp = array[index1];
    array[index1] = array[index2];
    array[index2] = tmp;
    }

    public static int findMinIndex(int[] data, int index) {
        int minIndex;
        if (index == data.length - 1)
        return index;
        minIndex = findMinIndex(data, index + 1);
        if (data[minIndex] < data[index])
        return minIndex;
        else
        return index;
        }



public static void main (String[] args) {

int[] numbers = {3, 15, 1, 9, 6, 12, 21, 17, 8}; }

my question is how can i run the program in the main?(whats the code to run the program) thanks.

1

1 Answer 1

2

Assuming this is all in a single class:

public static void main (String[] args) {
  int[] numbers = {3, 15, 1, 9, 6, 12, 21, 17, 8};
  selectionSort(numbers, 0, 8);
  System.out.println(Arrays.toString(numbers));
}
Sign up to request clarification or add additional context in comments.

2 Comments

print what? The result of the sort?
what value int high take in this method ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.