当前位置:网站首页>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));
}
}
边栏推荐
- 25 openwrt guest network add
- A little advice for students - how to build their own knowledge system?
- 校园流浪猫信息记录和分享的小程序源码
- [reach out to Party welfare] the easiest way to scan the H5 page in wechat
- 7/27 (board) dyeing method to determine bipartite graph + find combination number (recursive formula)
- About me writing a custom cell
- Shell rental reptile
- 【实战】使用 Web Animations API 实现一个精确计时的时钟
- Fedformer MOE module
- 网页源代码查看竟然有这么多方法!你都知道吗?
猜你喜欢

High number_ Chapter 4__ Curvilinear integral_ Exercise solution

Reading of papers on "towards generative aspect based sentimental analysis"

Thoroughly understand the sharing function in wechat games

Important SQL server functions - string utilities

功耗:Leakage Power

ESP8266 WIFI 模块和手机通信

Go structure

【实战】使用 Web Animations API 实现一个精确计时的时钟

重要的 SQL Server 函数 - 字符串实用程序

Information system project manager (2022) - key content: Project Portfolio Management (19)
随机推荐
Some personal understandings of openpose
@Requiredargsconstructor annotation
Harmony's Application on the shelves reported an error. The solution of "please use the API of the released version to develop the application and apply for listing"
VAE generation model (with VAE implementation MNIST code)
【YOLOv5实战5】基于YOLOv5的交通标志识别系统-YOLOv5整合PyQt5
重要的 SQL Server 函数 - 其他函数
RT thread changes the print serial port (add other functions on the basis of BSP)
Cyber Nuwa, how to make digital people?
Kingbasees Security Guide for Jincang database -- 5.2. data integrity protection
[blood vessel detection] Based on MATLAB mom method, combined with Hessian and curve fitting, blood vessel diameter measurement [including Matlab source code, 1970]
《关于我写自定义cell这件事》
Detailed explanation of pl/sql parameters ("box model")
Kotlin——函数
20-Openwrt crond crontab
Kingbasees Security Guide for Jincang database -- 6.1 introduction to strong authentication
[record of question brushing] 9. Number of palindromes
Domestic high hidden free agent crawler code
.net upload files through boundary
Slice slice
【sylar】框架篇-Chapter24-支持业务模块化