Last active
September 10, 2019 13:15
-
-
Save punkmonday/28d59e85b01ac82dc9c8bf3dcda6fb4e to your computer and use it in GitHub Desktop.
冒泡排序算法
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 characters
| import java.util.*; | |
| public class ShowMeBug { | |
| public static void main(String[] args) { | |
| int data[] = { 5, 4, 3, 2, 1 }; | |
| bubbleSort(data); | |
| System.out.println(Arrays.toString(data)); | |
| } | |
| public static void bubbleSort(int[] arr) { | |
| for (int i = 1; i < arr.length; i++) { | |
| for (int j = 0; j < arr.length - i; j++) { | |
| if (arr[j] > arr[j + 1]) { | |
| int temp = arr[j]; | |
| arr[j] = arr[j + 1]; | |
| arr[j + 1] = temp; | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment