Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 冒泡排序
- * @author lcw20
- *
- */
- public class BubbleSort {
- public static void sort(int[] arr) {
- for (int i = 0; i < arr.length; i++) {
- for (int j = i+1; j < arr.length; j++) {
- if (arr[i] > arr[j]) {
- int temp = arr[i];
- arr[i] = arr[j];
- arr[j] = temp;
- }
- }
- }
- }
- public static void main(String[] args) {
- int[] arr = new int[] {6,3,2,4,1};
- sort(arr);
- for (int i = 0; i < arr.length; i++) {
- System.out.println(arr[i]);
- }
- }
- }
Add Comment
Please, Sign In to add comment