博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
直接选择排序
阅读量:6939 次
发布时间:2019-06-27

本文共 591 字,大约阅读时间需要 1 分钟。

直接选择排序:

直接选择排序实质是一种交换排序.每次从待排序序列中选取关键字最小的元素,与当前元素交换,直到全部排序.

时间复杂度: O(n^2)-->O(n^2)

空间复杂度:O(1)

是否稳定排序:不稳定

void selectSort(int *array, int n){    for (int i = 0; i < n; ++i)    {        int smallIndex = i;        for (int j = i+1; j < n; ++j)        {            if (array[smallIndex] > array[j])            {                smallIndex = j;            }        }                if (i != smallIndex)        {            int temp = array[i];            array[i] = array[smallIndex];            array[smallIndex] = temp;                }    }}

 

转载于:https://www.cnblogs.com/RoamSpace/p/5659562.html

你可能感兴趣的文章
Mysql相关技术细节整理
查看>>
20160427Struts2--入门1
查看>>
如何搭建javaweb 开发环境
查看>>
输入年月日,看看格式是否正确。
查看>>
hotplug/mdev机制
查看>>
Deepin深度Linux系统安装记录
查看>>
.net OADate 转javascript的Datetime
查看>>
nova-network
查看>>
LAMP企业架构读写分离
查看>>
PHP高效率写法
查看>>
嵌套在母版页中的repeater自动生成控件ID
查看>>
数据访问层工具类
查看>>
16、SpringBoot------整合MapStruct
查看>>
应用各种领域逻辑模式组织业务逻辑层
查看>>
【原】Iframe with SimpleModal keeps breaking down in IE 9 IE 7
查看>>
Azure Active Directory Connect密码同步问题
查看>>
LoadLibrary("*.dll")失败 - 找不到指定的模块
查看>>
4.2.4 SQL Server数据库文件
查看>>
rails3 ajax替换成js
查看>>
Fix for: Permission denied to access property 'toString'
查看>>