当前位置:网站首页>选择排序
选择排序
2022-06-10 22:38:00 【Li_XiaoJin】
选择排序的相关内容。
选择排序的思路:
第一轮,找到最小的元素,和数组第一个数交换位置。
第二轮,找到第二小的元素,和数组第二个数交换位置...
直到最后一个元素,排序完成。
https://lixj.fun/upload/2021/07/%E9%80%89%E6%8B%A9%E6%8E%92%E5%BA%8Fgif-26451cec2bf841be838833ed2f27462c.gif
算法复杂度:O(n²)
算法空间复杂度:O(1)
算法稳定性:不稳定
public class SelectSort {
public static void sort(int[] arr) {
for (int i = 0; i < arr.length; i++) {
int minIndex = i;
for (int j = i; j < arr.length; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
if (minIndex != i) {
swap(arr, i, minIndex);
}
}
}
private static void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void main(String[] args) {
int[] arr = {10,7,2,4,7,62,3,4,2,1,8,9,19};
sort(arr);
System.out.println(Arrays.toString(arr));
}
}
Copyright: 采用 知识共享署名4.0 国际许可协议进行许可 Links:https://lixj.fun/archives/选择排序
边栏推荐
- C# Tryparse的用法
- Usage of C tryparse
- LabVIEW get IMAQ get last event coordinates
- LabVIEW open other exe programs
- 启牛的证券账户是真的吗?安全的吗?
- Two aspects of embedded audio development
- The time (in minutes) required for a group of workers to cooperate to complete the assembly process of a part are as follows:
- OpenVP*整合ldap认证
- Expandable to Max – MCU and MPU development, using the same license
- 2022年高考量化卷|请各位量化考生答题
猜你喜欢

Six procurement challenges perplexing Enterprises

VS的常用设置

Solve access denied for user 'root' @ 'localhost' (using password: yes)

怎么生成自动参考文献(简单 有图)

What is the workflow of dry goods MapReduce?

Solutions to the error reported by executing Oracle SQL statement [ora-00904: "createtime": invalid identifier] and [ora-00913: too many values]

HyperLeger Fabric安装

LabVIEW performs a serial loopback test

Postgraduate entrance examination English vocabulary unit1

300 questions on behalf of the first lecture on determinant
随机推荐
LabVIEW在波形图或波形图表上显示时间和日期
C语言创建动态二维数组
Two aspects of embedded audio development
OpenResty安装
Why is the kotlin language not popular now?
LabVIEW error "memory full - Application stopped on node"
The time (in minutes) required for a group of workers to cooperate to complete the assembly process of a part are as follows:
PHP实现iframe跨站替换文字/替换iframe网站文字的方法
Exception 0xc00000005 code occurred when LabVIEW called DLL
快速排序
What Fiddler does for testing
Data and information resource sharing platform (VII)
Fiddler simulates low-speed network environment
Apple CMS collection station source code - building tutorial - attached source code - new source code - development documents
Fiddler creates an autoresponder
OpenVP*整合ldap認證
csdn每日一练——有序表的折半查找
LabVIEW用高速数据流盘
SystemVerilog(十)-用户自定义类型
LabVIEW图片在从16位强制转换为8位后看起来要亮或暗