thought

The basic idea of bubble sort is to compare adjacent elements in pairs, swapping them so that each trip “floats” the smallest or largest element to the top, eventually reaching full order.

The illustration

Take the big upswing

Time complexity

O (N squared)

code

`

public static void bubbleSort(int[] arr){ if (arr == null || arr.length<2){ return; } for (int e = arr.length-1; e>0; For (int I =0; int I =0; int I =0; i<e; I++) {if (arr [I] > arr [I + 1]) {/ / exchange swap (arr, I, I + 1); } } } } public static void swap(int[] arr,int i,int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; }Copy the code

`