Bubble sorting of basic algorithm series

Bubble sorting is a must-learn content for introductory algorithms. Just like "Orchid Grass" and "Just Like Your Gentleness" when practicing guitar, they are both basic opening content.
The principle of bubbling sorting is "precipitation of large numbers, bubbling of decimals; double loop, two rounds of control." The basic code is as follows:

public static void bubbleSort(int[]arr){
	for(int i=0;i<arr.length-1;i++){		//控制轮次
		for(int j=0;j<arr.length-1-i;j++){		//两个数依次比较
			if(arr[j]>arr[j+1]){		//两个数交换条件,确保小数冒泡到数组前面
				int temp=arr[j];
				arr[j]=arr[j+1];
				arr[j+1]=temp;
			}
		}
	}
} 

Guess you like

Origin blog.csdn.net/langxiaolin/article/details/111937638
Recommended