当前位置:网站首页>Select sort
Select sort
2020-11-08 18:38:00 【Irving the procedural ape】
The principle of the selection sorting algorithm is to find the smallest element in the array , Then exchange it with the first element of the array , Then find the smallest of the remaining elements , Then switch to the second element of the array , And so on , Until all the elements are sorted
The simple implementation is as follows :
1 package Selection sort ; 2 3 public class DemoMain { 4 public static void main(String[] args) { 5 Integer[] a = {5, 2, 6, 3, 4, 7}; 6 sort(a); 7 System.out.println(isSorted(a)); 8 show(a); 9 }10 11 /**12 * Sort 13 * @param a Sorted array 14 */15 public static void sort(Comparable[] a) {16 for (int i = 0; i < a.length - 1; i++) {17 // Get the subscript of the element to be exchanged 18 int index = i;19 // Find the smallest element , Assign subscript to index20 for (int j = i + 1; j < a.length; j++) {21 if (less(a[index], a[j])) {22 index = j;23 }24 }25 // Pass the subscript of the element to be exchanged i And the subscript of the minimum index26 exch(a, i, index);27 }28 }29 30 /**31 * Compare the size ,v > w The value is greater than 032 * Use compareTo It's because the reference type implements Comparable Interface 33 * @param v Parameters passed in the sort method 134 * @param w35 * @return Return the judgment result 36 */37 private static b.........
版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢
边栏推荐
猜你喜欢
Summary of interface test case ideas
Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
(O)ServiceManager分析(一)之BinderInternal.getContextObject
[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!
Use markdown
c++ opencv4.3 sift匹配
Flink series (0) -- Preparation (basic stream processing)
Implementation of warehouse management system with ABP (net core) + easyUI + efcore
Summary: in October, more investment management strategies have come to the new overseas defi project!
解决go get下载包失败问题
随机推荐
Python 列表的11个重要操作
Design by contract (DBC) and its application in C language
后缀表达式转中缀表达式
给大家介绍下,这是我的流程图软件 —— draw.io
go语言参数传递到底是传值还是传引用?
Simple process of reading pictures by QT program developed by Python
The interface testing tool eolinker makes post request
read文件一个字节实际会发生多大的磁盘IO?
SQL 速查
Regular backup of WordPress website program and database to qiniu cloud
Application of four ergodic square of binary tree
Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
I used Python to find out all the people who deleted my wechat and deleted them automatically
在Python中创建文字云或标签云
Wechat applet related
API生命周期的5个阶段
MongoDB增删改查操作
WebGL 水波及焦散(刻蚀)的渲染总结
How much faster is a server equipped with a SSD than a mechanical hard disk
Framework - SPI four modes + general device driver implementation - source code