当前位置:网站首页>选择排序法
选择排序法
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));
}
边栏推荐
猜你喜欢
Unity转微信小游戏与JS交互
Pytorch Daily Practice - Predicting Surviving Passengers on the Titanic
【Rhapsody学习笔记】1:Hello World
IDEA overview and installation and debugging
Wlan实验(ENSP)
小型网站组建(ENSP)
crontab timing operation
Wangeditor rich text editor to upload pictures and solve cross-domain problems
对称加密和非对称加密
DOM操作-事件的绑定与解绑
随机推荐
【Rhapsody学习笔记】3:Dishwasher
JDBC的使用
Webrtc从理论到实践二: 架构
对称加密和非对称加密
Three methods of accessing image pixels in opencv
记一次QT 2D 画图 实现3D动态效果
UR3机器人运动学分析之正运动学分析
Solution for MySQL The table is full
5G的用途和工作原理
Attention based ASR(LAS)
ES6-Map和Set
Learning and understanding of ROS service programming
C语言数组的深度分析
Pytorch study notes 13 - Basic_RNN
When solving background-size:cover, the picture is covered but not displayed completely?
webdriver.定位元素
Detailed explanation of mysql transaction principle
IDEA overview and installation and debugging
Incredibuild 宣布支持 Yocto
概率论相关笔记