Last active
May 8, 2018 01:27
-
-
Save namkyu/cc0ee5edd3d550d928ef18c697e8bde1 to your computer and use it in GitHub Desktop.
Revisions
-
namkyu renamed this gist
May 8, 2018 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ #### selection sort ``` @Test public void selectionSort() { int[] array = {10, 8, 99, 7, 1, 5, 88, 9}; @@ -25,9 +26,10 @@ private static void selection_sort(int[] input) { input[min] = temp; } } ``` #### reverse ``` @Test public void reverse() { String str = "Reverse this string"; @@ -45,3 +47,4 @@ public void reverse() { System.out.println(String.format("In:%s", str)); System.out.println(String.format("Out:%s", sOut)); } ``` -
namkyu renamed this gist
May 8, 2018 . 1 changed file with 3 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ ## selection sort @Test public void selectionSort() { int[] array = {10, 8, 99, 7, 1, 5, 88, 9}; @@ -26,10 +25,9 @@ private static void selection_sort(int[] input) { input[min] = temp; } } ## reverse @Test public void reverse() { String str = "Reverse this string"; @@ -47,4 +45,3 @@ public void reverse() { System.out.println(String.format("In:%s", str)); System.out.println(String.format("Out:%s", sOut)); } -
namkyu revised this gist
May 8, 2018 . 1 changed file with 21 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,4 +26,25 @@ private static void selection_sort(int[] input) { input[min] = temp; } } ``` #### reverse ``` @Test public void reverse() { String str = "Reverse this string"; int slength = str.length(); int end = slength - 1; char[] buf = new char[str.length()]; for (int i = end; i != -1; i--) { buf[(end) - i] = str.charAt(i); } String sOut = new String(buf); System.out.println(String.format("In:%s", str)); System.out.println(String.format("Out:%s", sOut)); } ``` -
namkyu created this gist
May 8, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ #### selection sort ``` @Test public void selectionSort() { int[] array = {10, 8, 99, 7, 1, 5, 88, 9}; selection_sort(array); System.out.println(Arrays.toString(array)); } private static void selection_sort(int[] input) { int inputLength = input.length; for (int i = 0; i < inputLength - 1; i++) { int min = i; // find the first, second, third, fourth... smallest value for (int j = i + 1; j < inputLength; j++) { if (input[j] < input[min]) { min = j; } } // swaps the smallest value with the position 'i' int temp = input[i]; input[i] = input[min]; input[min] = temp; } } ```