选择排序
来源:互联网 发布:2016淘宝新店如何运营 编辑:程序博客网 时间:2024/05/18 02:12
package test;
public class SelectSort {
/*
* 直接选择排序(也是两个循环结构) 只需要找出最小值的左边
*/
public static void main(String[] args) {
int arr[] = { 9, 4, 3, 1, 8, 2, 5, 6 };
sort(arr);
for (int k = 0; k < arr.length; k++) {
System.out.print(arr[k] + " ");
}
}
public static void sort(int[] arr) {
for (int i = 0; i < arr.length - 1; i++) {
int minIndex = i;//定义一个最小值
for (int j = i + 1; j < arr.length - 1; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
int temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
}
}
}
public class SelectSort {
/*
* 直接选择排序(也是两个循环结构) 只需要找出最小值的左边
*/
public static void main(String[] args) {
int arr[] = { 9, 4, 3, 1, 8, 2, 5, 6 };
sort(arr);
for (int k = 0; k < arr.length; k++) {
System.out.print(arr[k] + " ");
}
}
public static void sort(int[] arr) {
for (int i = 0; i < arr.length - 1; i++) {
int minIndex = i;//定义一个最小值
for (int j = i + 1; j < arr.length - 1; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
int temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
}
}
}
0 0
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序:
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 交换排序
- 向HTCondor集群提交LS-DYNA任务
- Spring中将一个对象数据显示在前端的列表中
- python exp()
- Error:Execution failed for task ':app:processDebugResources'.
- 选择排序
- hadoop_cluser
- 伪逆矩阵
- 查询词提示系统的简单实现
- 最小生成树Prim
- 在unity的player角色控制中实现MVC模式
- Spring与Hibernate整合小细节与测试问题
- python获取操作系统平台、版本及架构
- 关于PowerBuilder启动时出现磁盘符号的解决办法