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 — leetcode/basic/sorting/SelectionSort/SelectionSort.java at main · kim8796/leetcode Expand file tree/ Copy pathSelectionSort.javaMore file actions 28 lines (24 loc) · 718 Bytes / Copy pathSelectionSort.javaFile metadata and controls28 lines (24 loc) · 718 Bytes 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 import java.util.Arrays; public class SelectionSort { private static void selectionSort(int[] nums) { for (int i = 0, n = nums.length; i < n - 1; ++i) { int minIndex = i; for (int j = i; j < n; ++j) { if (nums[j] < nums[minIndex]) { minIndex = j; } } swap(nums, minIndex, i); } } private static void swap(int[] nums, int i, int j) { int t = nums[i]; nums[i] = nums[j]; nums[j] = t; } public static void main(String[] args) { int[] nums = {1, 2, 7, 9, 5, 8}; selectionSort(nums); System.out.println(Arrays.toString(nums)); } } |
| You are visitor 01402775 — 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. |