Class Sort


  • public class Sort
    extends Object
    All kind of Sort algorithm implemented method use the default compare method
    Author:
    chenxin
    • Constructor Detail

      • Sort

        public Sort()
    • Method Detail

      • insertionSort

        public static <T extends Comparable<? super T>> void insertionSort​(T[] arr)
        insert sort method
        Parameters:
        arr - an array of a comparable items
      • shellSort

        public static <T extends Comparable<? super T>> void shellSort​(T[] arr)
        shell sort algorithm
        Parameters:
        arr - an array of Comparable items
      • mergeSort

        public static <T extends Comparable<? super T>> void mergeSort​(T[] arr)
        merge sort algorithm
        Parameters:
        arr - an array of Comparable item
      • quicksort

        public static <T extends Comparable<? super T>> void quicksort​(T[] arr)
        quick sort algorithm
        Parameters:
        arr - an array of Comparable items
      • insertionSort

        public static <T extends Comparable<? super T>> void insertionSort​(T[] arr,
                                                                           int start,
                                                                           int end)
        method to sort an subarray from start to end with insertion sort algorithm
        Parameters:
        arr - an array of Comparable items
        start - the begining position
        end - the end position
      • quickSelect

        public static <T extends Comparable<? super T>> void quickSelect​(T[] arr,
                                                                         int k)
        quick select algorithm
        Parameters:
        arr - an array of Comparable items
        k - the k-th small index
      • bucketSort

        public static void bucketSort​(int[] arr,
                                      int m)
        bucket sort algorithm
        Parameters:
        arr - an int array
        m - the large-most one for all the Integers in arr
      • bucketSort

        public static void bucketSort​(Integer[] arr,
                                      int m)
        bucket sort algorithm
        Parameters:
        arr - an array of Integer items
        m - the large-most one for all the Integers in arr