Skip to content

Instantly share code, notes, and snippets.

@namkyu
Last active May 8, 2018 01:27
Show Gist options
  • Save namkyu/cc0ee5edd3d550d928ef18c697e8bde1 to your computer and use it in GitHub Desktop.
Save namkyu/cc0ee5edd3d550d928ef18c697e8bde1 to your computer and use it in GitHub Desktop.

Revisions

  1. namkyu renamed this gist May 8, 2018. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions algorithm.java → algorithm.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    ## selection sort
    #### 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
    #### 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));
    }
    ```
  2. namkyu renamed this gist May 8, 2018. 1 changed file with 3 additions and 6 deletions.
    9 changes: 3 additions & 6 deletions algorithm.md → algorithm.java
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    #### selection sort
    ```
    ## 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
    ```

    ## 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));
    }
    ```
  3. namkyu revised this gist May 8, 2018. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions algorithm.md
    Original 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));
    }
    ```
  4. namkyu created this gist May 8, 2018.
    29 changes: 29 additions & 0 deletions algorithm.md
    Original 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;
    }
    }
    ```