当前位置:网站首页>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));
}
}
边栏推荐
- Notes to subject 2
- What is the account opening process of qiniu business school? Is it safe?
- 方舟生存进化自建服务器要多少成本?
- RT thread changes the print serial port (add other functions on the basis of BSP)
- Domestic high hidden free agent crawler code
- 重要的 SQL Server 函数 - 数字函数
- Information system project manager (2022) - key content: Project Risk Management (11)
- Campus stray cat information recording and sharing applet source code
- 【sylar】框架篇-Chapter24-支持业务模块化
- 【day03】流程控制语句
猜你喜欢

Go结构体

IPC: multi process binder Aidl user guide, including cases
![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

The simulation test disconnects the server from the public network

Information system project manager (2022) - key content: information system integrated testing and management, project management maturity model, quantitative project management (21)

RT-Thread改变打印串口(在BSP的基础上添加其他功能)

Important SQL server functions - date functions

Esp8266 WiFi module and mobile communication
![[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]

10 more advanced open source command line tools
随机推荐
Go grpc: a solution of connection reset by peer
Some personal understandings of openpose
Study of the Intel aria 10 Avalon mm DMA interface for PCI Express solutions User Guide
[day03] process control statement
[coding and decoding] Huffman coding and decoding based on Matlab GUI [including Matlab source code 1976]
【牛客】求1+2+3+...+n
Fearless of side impact damage, Chery arize 8 fully protects the safety of passengers
"Three no's and five requirements" principle of enterprise Digitalization Construction
重要的 SQL Server 函数 - 其他函数
《KG-BERT: BERT for Knowledge Graph Completion》
Go结构体
[yolov5 practice 5] traffic sign recognition system based on yolov5 -yolov5 integration pyqt5
Bio annotation of emotion analysis aste triples extraction
金仓数据库KingbaseES安全指南--4 数据访问保护
Un7.27: common commands of redis database.
Power consumption: leakage power
@Requiredargsconstructor annotation
RN interface jump description
Information system project manager (2022) - key content: Project Procurement Management (12)
Efficient practice intelligent analysis of massive log data in aviation industry