Skip to content

Instantly share code, notes, and snippets.

@punkmonday
Last active September 10, 2019 13:15
Show Gist options
  • Select an option

  • Save punkmonday/28d59e85b01ac82dc9c8bf3dcda6fb4e to your computer and use it in GitHub Desktop.

Select an option

Save punkmonday/28d59e85b01ac82dc9c8bf3dcda6fb4e to your computer and use it in GitHub Desktop.
冒泡排序算法
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