选择排序-SelectionSort
来源:互联网 发布:天猫淘宝店差评有用吗 编辑:程序博客网 时间:2024/06/07 22:40
算法思想:
从所有序列中先找到最小的,然后放到第一个位置。之后再看剩余元素中最小的,放到第二个位置……以此类推,就可以完成整个的排序工作了。可以很清楚的发现,选择排序是固定位置,找元素,然后将元素调整到指定位置。
代码:
class SlectionSort{public: void selectionSort(vector<int> &nums){ int length=nums.size(); int index; for(int i=0;i<length-1;i++){ index=i; for(int j=i;j<length;j++){ if(nums[j]<nums[index]){ index=j; } } swap(nums[i],nums[index]); } }};
算法复杂度:O(n^2)
0 0
- 选择排序-SelectionSort
- 选择排序SelectionSort
- 选择排序 - SelectionSort
- 选择排序SelectionSort
- 选择排序(1)SelectionSort
- SelectionSort -- 选择排序(C++)
- c/c++选择排序(SelectionSort)
- 2-1选择排序 selectionSort
- 排序算法 之 选择排序SelectionSort
- 经典算法-选择排序(SelectionSort)
- Java排序算法(七)--简单选择排序(SelectionSort)
- 【算法导论学习-003】选择排序(SelectionSort)
- 快速排序(SelectionSort)
- Java排序再巩固--SelectionSort
- SelectionSort
- selectionSort
- selectionSort
- selectionSort
- 先考虑原则、公理和类比、再考虑个人意见和口味
- 关于scrollView自动布局
- keil新建第一个工程
- js 跨域问题常见的五种解决方式
- GridView——MasterDetail设置
- 选择排序-SelectionSort
- 正确使用 CocoaPods
- 1天 等于 86400 秒?
- 一台电脑安装2个不同版本的jdk
- C++ Builder 将数据库数据导出到Excel中总结2
- iOS URLWithString返回为空nil的解决方案
- Chico and Dico ——根据任意4张扑克猜第5张牌
- Python 打log
- java垃圾回收算法