当前位置:网站首页>Select sorting method
Select sorting method
2022-07-28 04:28:00 【Jiang CI ࿐】
One 、 Introduction to selective sorting method
Selection sort (Selection sort) It is a simple and intuitive sorting algorithm , It is in a set of numbers to sort , Choose the smallest ( Or maximum ) Exchange a number of with the number of the first position ; Find the smallest number among the remaining numbers and exchange it with the number in the second position , That is, the sequence is placed at the end of the ordered sequence , So circular , Until all data elements are arranged .
Two 、 The basic principle
Select the smallest data element from the data elements to be sorted for the first time ( Or maximum ) An element of , Store at the beginning of the sequence , And then find the smallest of the remaining unsorted elements ( Big ) Elements , Then put it at the end of the sorted sequence .
And so on , Until the number of all data elements to be sorted is zero .
Selective sorting is an unstable sorting method .
demonstration
Original value :55,23,87,62,16
First scan : First find the minimum value in the sequence , Then exchange with the first element in the sequence
16,23,87,62,55
Second scan : Start with the second item , Find the lowest value in this series except the first item , Then exchange positions with the second element
16,23,87,62,55
The third scan : Start with the third item
16,23,55,62,87
Fourth scan : Start with Item 4
16,23,55,62,87

3、 ... and 、 Implementation code (java)
import java.util.Arrays;
public class practice {
public static void main(String []args) {
int array[]= {
1,2,35,8,9,};
for (int i = 0; i < array.length-1; i++) {
int minIndex=i;
int min=array[i];
for (int j = i+1; j < array.length; j++) {
if (min>array[j])
{
min=array[j];
minIndex=j;
}
}
array[minIndex]=array[i];
array[i]=min;
}
System.out.println(Arrays.toString(array));
}
}
边栏推荐
- 【YOLOv5实战5】基于YOLOv5的交通标志识别系统-YOLOv5整合PyQt5
- 方舟生存进化自建服务器要多少成本?
- The unsatisfied analysis of setup and hold timing is the solution
- 仿真测试断开服务器公网连接
- C # cross thread refresh foreground UI
- C#跨线程刷新前台UI
- [blood vessel detection] Based on MATLAB mom method, combined with Hessian and curve fitting, blood vessel diameter measurement [including Matlab source code, 1970]
- A little advice for students - how to build their own knowledge system?
- 《关于我写自定义cell这件事》
- Kingbasees Security Guide for Jincang database -- 5.2. data integrity protection
猜你喜欢

Kotlin -- function

仿真测试断开服务器公网连接

@Requiredargsconstructor annotation
![[kinematics] simulation of orbital angular momentum based on MATLAB [including Matlab source code 1971]](/img/5e/dfe029490183ee74687606941ce98e.jpg)
[kinematics] simulation of orbital angular momentum based on MATLAB [including Matlab source code 1971]

校园流浪猫信息记录和分享的小程序源码

Un7.27: how to successfully build a ruoyi framework project in idea?
![RuntimeError: stack expects each tensor to be equal size, but got [8] at entry 0 and [2] at entry 2](/img/66/27de1ac0f642fc91fca5196ea6e141.png)
RuntimeError: stack expects each tensor to be equal size, but got [8] at entry 0 and [2] at entry 2

glusterfs 文件未挂载,权限: r-s

Network visualization: features of convolution kernel and CNN visualization (through the attention part of gradient visualization network)
![[yolov5 practice 5] traffic sign recognition system based on yolov5 -yolov5 integration pyqt5](/img/81/89b8e38801f706ef396943a79ef4c5.png)
[yolov5 practice 5] traffic sign recognition system based on yolov5 -yolov5 integration pyqt5
随机推荐
写给学生的一点建议-如何构建自己的知识体系?
Information system project manager (2022) - key content: information system integrated testing and management, project management maturity model, quantitative project management (21)
24-Openwrt dnsmasq
【sylar】框架篇-Chapter22-辅助模块
Some personal understandings of openpose
What technical capabilities should a qualified software testing engineer have?
[reach out to Party welfare] the easiest way to scan the H5 page in wechat
Shanghai Telecom released public computing services and signed the action plan of "Joint Innovation Center for intelligent computing applications" with Huawei and other partners
将数据库拿到的数据渲染到elementUI 中的table中去
MySQL:数据类型和运算符
RuntimeError: stack expects each tensor to be equal size, but got [8] at entry 0 and [2] at entry 2
IPC: multi process binder Aidl user guide, including cases
Docking with Hang Seng express ― dolphin DB NSQ plug-in tutorial
【sylar】框架篇-Chapter21-环境变量模块
idea2022更改本地仓库,配置阿里云中央仓库
The simulation test disconnects the server from the public network
Solana「迷惑行为」:造手机、开门店
[yolov5 practice 5] traffic sign recognition system based on yolov5 -yolov5 integration pyqt5
Ffmpeg common instructions
Password key hard coding check