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/sort/BubbleSort.java at master · skyformat99/leetcode Expand file tree/ Copy pathBubbleSort.javaMore file actions 28 lines (25 loc) · 772 Bytes / Copy pathBubbleSort.javaFile metadata and controls28 lines (25 loc) · 772 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 BubbleSort { private static void swap(int[] nums, int i, int j) { int t = nums[i]; nums[i] = nums[j]; nums[j] = t; } private static void bubbleSort(int[] nums) { boolean hasChange = true; for (int i = 0; i < nums.length - 1 && hasChange; ++i) { hasChange = false; for (int j = 0; j < nums.length - 1 - i; ++j) { if (nums[j] > nums[j + 1]) { swap(nums, j, j + 1); hasChange = true; } } } } public static void main(String[] args) { int[] nums = {1, 2, 7, 9, 5, 8}; bubbleSort(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. |