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 — algorithm_basic_java/src/test/java/sort/SelectionSort.java at master · jbee37142/algorithm_basic_java Expand file tree/ Copy pathSelectionSort.javaMore file actions 45 lines (38 loc) · 1.1 KB / Copy pathSelectionSort.javaFile metadata and controls45 lines (38 loc) · 1.1 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 package sort; import org.junit.Test; import utils.Utils; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; public class SelectionSort { /* TASK Selection sort를 구현한다. */ @Test public void test() { int[] arr1 = {}; int[] sortedArr1 = {}; assertThat(solution(arr1), is(sortedArr1)); int[] arr2 = {6,4,1,8,9,2,7,5,3}; int[] sortedArr2 = {1,2,3,4,5,6,7,8,9}; assertThat(solution(arr2), is(sortedArr2)); int[] arr3 = {1}; int[] sortedArr3 = {1}; assertThat(solution(arr3), is(sortedArr3)); } public int[] solution(int[] arr) { if (arr == null) return null; int[] result = arr; int maxPos; for (int i = 0; i < result.length - 1; i++) { maxPos = i; for (int k = i + 1; k < result.length; k++) { if (result[maxPos] > result[k]) { maxPos = k; } } result = Utils.swapValue(result, i, maxPos); } return result; } } |
| You are visitor 01402503 — 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. |