当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- [open source]. Net uses ORM to access Huawei gaussdb database
- 一分钟全面看懂forsage智能合约全球共享以太坊矩阵计划
- 使用Fastai开发和部署图像分类器应用
- Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020
- WordPress网站程序和数据库定时备份到七牛云图文教程
- Opencv solves the problem of ippicv download failure_ 2019_ lnx_ intel64_ general_ 20180723.tgz offline Download
- Mongodb database
- TypeScript(1-2-2)
- 苏州游记
- SQL 速查
猜你喜欢

使用基于GAN的过采样技术提高非平衡COVID-19死亡率预测的模型准确性

How much faster is a server equipped with a SSD than a mechanical hard disk

学会了volatile,你变心了,我看到了

Iptables from introduction to mastery

接口测试工具Eolinker进行post请求

不是程序员,代码也不能太丑!python官方书写规范:任何人都该了解的 pep8

AI perfume is coming. Will you buy it?

解决go get下载包失败问题

为什么需要使用API管理平台

在Python中创建文字云或标签云
随机推荐
Infix expression to suffix expression
vim-配置教程+源码
To introduce to you, this is my flow chart software—— draw.io
Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
Hello world of rabbitmq
RSA asymmetric encryption algorithm
experiment
Wechat applet related
后缀表达式转中缀表达式
Framework - SPI four modes + general device driver implementation - source code
[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!
PAT_甲级_1056 Mice and Rice
Brief VIM training strategy
abp(net core)+easyui+efcore实现仓储管理系统——出库管理之五(五十四)
腾讯:阿里的大中台虽好,但也不是万能的!
使用K3S创建本地开发集群
Development of uni app imitating wechat app
An online accident caused by improper use of thread pool
Solution to the problem of offline connection between ADB and mobile phone
VirtualBox安装centos7