当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Tencent: Although Ali's Taichung is good, it is not omnipotent!
- SQL quick query
- 给大家介绍下,这是我的流程图软件 —— draw.io
- PHP生成唯一字符串
- Use markdown
- Django之简易用户系统(3)
- [elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!
- Travel notes of Suzhou
- Builder pattern
- Django之简易用户系统(3)
猜你喜欢
Travel notes of Suzhou
Application of four ergodic square of binary tree
The interface testing tool eolinker makes post request
PHP生成唯一字符串
使用Fastai开发和部署图像分类器应用
experiment
Development of uni app imitating wechat app
If the programming language as martial arts unique! C++ is Jiu Yin Jing. What about programmers?
Part I - Chapter 1 Overview
解决go get下载包失败问题
随机推荐
Chapter 5 programming
第二章编程练习
An online accident caused by improper use of thread pool
Introduction to latex
Express框架
markdown使用
LiteOS-消息队列
给大家介绍下,这是我的流程图软件 —— draw.io
TypeScript(1-2-2)
搭载固态硬盘的服务器究竟比机械硬盘快多少
npm install 无响应解决方案
佛萨奇forsage以太坊智能合约是什么?以太坊全球滑落是怎么回事
Opencv solves the problem of ippicv download failure_ 2019_ lnx_ intel64_ general_ 20180723.tgz offline Download
聊聊Go代码覆盖率技术与最佳实践
VirtualBox install centos7
Solution to the problem of offline connection between ADB and mobile phone
Flink's sink: a preliminary study
uni-app实战仿微信app开发
[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!
Chapter 2 programming exercises