payal-kothari
6/22/2017 - 7:09 AM

https://www.youtube.com/watch?v=f8hXR_Hvybo (https://www.youtube.com/watch?v=f8hXR_Hvybo)

public class MySelectionSort { 

    public static int[] doSelectionSort(int[] arr){ 

        for (int i = 0; i < arr.length - 1; i++) 
        { 
            int index = i; 
            for (int j = i + 1; j < arr.length; j++) 
                if (arr[j] < arr[index]) 
                    index = j; 

            int smallerNumber = arr[index]; 
            arr[index] = arr[i]; 
            arr[i] = smallerNumber; 
        } 
        return arr; 
    } 

    public static void main(String a[]){ 

        int[] arr1 = {10,34,2,56,7,67,88,42}; 
        int[] arr2 = doSelectionSort(arr1); 
        for(int i:arr2){ 
            System.out.print(i); 
            System.out.print(", "); 
        } 
    } 
}