Java - Selection Sort Algorithm

后端 未结 17 1623
我在风中等你
我在风中等你 2020-12-17 04:26

I have some questions about selection sort.I\'m a little bit confused.

 int [] arr = {5,4,3,2,1}; // This is my array
    int min = 0;

    for(int i = 0;i&l         


        
17条回答
  •  旧巷少年郎
    2020-12-17 04:54

    Just pass array and size of array

    private void selectionSort() {
        for (int i = 0; i < arraySize; i++) {
            for (int j = i; j < arraySize; j++) {
                if (array[i] > array[j])
                    swapValues(i,j);
            }
        }
    }
    private void swapValues(int posOne, int posTwo) {
        int tValue = array[posOne];
        array[posOne] = array[posTwo];
        array[posTwo] = tValue;
    }
    

提交回复
热议问题