GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/Sorts/InsertionSort.java at master · feinoah/Java Expand file tree/ Copy pathInsertionSort.javaMore file actions 61 lines (47 loc) · 1.4 KB / Copy pathInsertionSort.javaFile metadata and controls61 lines (47 loc) · 1.4 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 package Sorts; import static Sorts.SortUtils.less; import static Sorts.SortUtils.print; /** * * @author Varun Upadhyay (https://github.com/varunu28) * @author Podshivalov Nikita (https://github.com/nikitap492) * */ class InsertionSort implements SortAlgorithm { /** * This method implements the Generic Insertion Sort * Sorts the array in increasing order * * @param array The array to be sorted * **/ @Override public <T extends Comparable<T>> T[] sort(T[] array) { for (int j = 1; j < array.length; j++) { // Picking up the key(Card) T key = array[j]; int i = j - 1; while (i >= 0 && less(key, array[i])) { array[i + 1] = array[i]; i--; } // Placing the key (Card) at its correct position in the sorted subarray array[i + 1] = key; } return array; } // Driver Program public static void main(String[] args) { // Integer Input Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12}; InsertionSort sort = new InsertionSort(); sort.sort(integers); // Output => 1 4 6 9 12 23 54 78 231 print(integers); // String Input String[] strings = {"c", "a", "e", "b","d"}; sort.sort(strings); //Output => a b c d e print(strings); } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |