Selection and sorting of basic algorithm series

Selective sorting is also a must-learn content for introductory algorithms. Like bubble sorting, it is the opening content of basic algorithms. The same point with bubble sort is that the time complexity is O(n*n), and the difference is that the sorting category that it may belong to is different. Bubble sort and quick sort are both exchange sort series, simple selection sort and heap sort are both Select the sort series.
The criterion for selecting sorting is "double loop, two-round control; set one to compare, change the order of size" and the basic code is as follows:

public static void selectSort(int[]arr){
	for(int i=0;i<arr.length;i++){   //控制轮次
 		for(int j=i+1;j<arr.length;j++){   //两个数依次比较
  			if(arr[i]>arr[j]){   //两个数交换条件,依次把i和i之后的数比较
  				int temp=arr[i];
   				arr[i]=arr[j];
   				arr[j]=temp;
			}
		}
	}
} 

Guess you like

Origin blog.csdn.net/langxiaolin/article/details/111998771