Monday, June 30, 2014

Selection Sort in Java

For theoretical reference you can see wiki link.
http://en.wikipedia.org/wiki/Selection_sort

For programmatic reference you can check this.

public class SelectionSort {
   
    public static void main(String[] args) {
        int [] arr = {3, 4, 2, 1, 5, 10, 99, 12, 1, 7};
        showAll(descSort(arr));
    }

    private static int [] descSort(int[] arr){
        for(int i = 0; i <= arr.length -1; i++){
            for(int j = i+1; j < (arr.length); j++){
                if(arr[i] > arr[j]){
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        return arr;
    }
   
    private static void showAll(int[] arr){
        for (int i : arr) {
            System.out.println("" + i);
        }
    }
}

1 comment:

  1. Android SDK allows you to create stunning mobile application loaded with more features and enhanced priority. With basis on Java coding language, you can create stunning mobile application with ease.

    Cado Magenge
    ”http://appdevelopmentcompany.com.au/ipad-application-development.html”
    ”http://appdevelopmentcompany.com.au/custom-web-development.html”
    “http://appdevelopmentcompany.com.au/android-application-development.html”
    "http://www.appdevelopmentcompany.com.au/responsive-web-design.html"

    ReplyDelete