选择排序

一、概念

每一趟从待排序的数据元素中选出最小(最大)的一个元素,放在已排好序的最前(最后),直到全部待排序的数据元素排完。

二、复杂度

排序方法最差时间分析最好时间分析平均时间复杂度空间复杂度稳定性
选择排序O(n2)O(n2)O(n2)O(1)稳定

三、代码实现

 1     //选择排序算法
 2     public void selectsort(int[] array){
 3         if(array.length == 0 || array == null)
 4             return;
 5         //每次选择最小的到最前
 6         for(int i = 0; i < array.length; i++){
 7             int min = i;
 8             for(int j = i+1; j < array.length; j++){
 9                 if(array[min] > array[j])
10                     min = j;
11             }
12             if(i != min){
13                 int temp = array[min];
14                 array[min] = array[i];
15                 array[i] = temp;
16             }
17             printArray(array,i+1);
18         }
19     }
20     public void printArray(int a[],int count){
21         if(count != 0)
22         System.out.print("第" + count + "次   ");
23         for(int m = 0; m < a.length; m++){
24             if(count == m && count != 0)
25                 System.out.print("|");
26             System.out.print(a[m] + " ");
27         }
28         System.out.println();
29     }
30     public static void main(String[] args) {
31         int a[] = {11,7,6,1,8,4,3,2};
32         SelectSort bs = new SelectSort();
33         bs.selectsort(a);
34     }

冒泡排序

快速排序

堆排序

插入排序

希尔排序(缩小增量排序)

归并排序-递归实现

基数排序

转载于:https://www.cnblogs.com/fankongkong/p/7247500.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值