当前位置:网站首页>选择排序法
选择排序法
2022-07-31 05:19:00 【想要飞翔的企鹅】
选择排序法的思路:在数组中选出最小的然后将其与放在数组最左侧位置的值互换,最右侧位置的值,就确定下来了,抛除最右侧值,然后重复上诉做法,一直到结束。
public static void main(String[] args) {
int[] arr = {9, 6, 12, 8, 15, 11, 10, 1};
for (int j = 0; j < arr.length-1; j++) {
int indexMin = j;
int valueMin = arr[j];
boolean flag = false;
for (int i = j+1; i < arr.length; i++) {
if (valueMin > arr[i]) {
indexMin = i;
valueMin = arr[i];
}
}
if (indexMin != j) {
arr[indexMin] = arr[j];
arr[j] = valueMin;
}
}
System.out.println(Arrays.toString(arr));
}
边栏推荐
猜你喜欢

【Rhapsody学习笔记】4:Relations

IDEA overview and installation and debugging

ImportError: cannot import name 'Xxxx' from partially initialized module 'xx.xx.xx'

DingTalk Enterprise Internal-H5 Micro Application Development

Pytorch study notes 10 - detailed explanation of convolutional neural network and application of multi-classification task of mnist dataset

哈希表基础

APP测试:测试流程及常规测试内容

链表理论基础

Qt TreeView 问题记录

Websocket协议解析与QT代码示例
随机推荐
ES6-新增的基本数据:Symbol
衡量 DevOps 成功与否的重要度量指标
Detailed explanation of mysql transaction principle
crontab timing operation
C语言对文件的操作(完整版)
Debian 搭建 WireGuard 服务端
【博学谷学习记录】超强总结,用心分享 | 软件测试 UnitTest框架
cenos7配置IP,配置IP不生效
Unity加载GIf动画
读写文件,异常,模块和包
MySQL free installation download and configuration tutorial
力扣刷题之排序链表
在 AWS 上从零开始设置 Incredibuild 构建系统
闭包,装饰器,类方法,静态方法,委托属性
Solution for MySQL The table is full
Log jar package conflict, and its solution
ES6-对象
Virtual machine view port number process
PyTorch Study Notes 08 - Loading Datasets
【内网开发日记】用websocket手搓一个聊天软件