当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Talk about go code coverage technology and best practices
- I used Python to find out all the people who deleted my wechat and deleted them automatically
- 第二章编程练习
- 性能压测时,并发压力增加,系统响应时间和吞吐量如何变化
- AI香水来了,你会买吗?
- Five phases of API life cycle
- Jsliang job series - 07 - promise
- An online accident caused by improper use of thread pool
- 后缀表达式转中缀表达式
- 趣文分享:C 语言和 C++、C# 的区别在什么地方?
猜你喜欢

experiment

前后端分离跨域问题解决方案

PAT_甲级_1056 Mice and Rice

Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020

Chapter 5 programming

Package subsystem in Simulink

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

go语言参数传递到底是传值还是传引用?

简明 VIM 练级攻略
![[open source]. Net uses ORM to access Huawei gaussdb database](/img/f8/50715c25a9d49b010cba2ff442c04e.jpg)
[open source]. Net uses ORM to access Huawei gaussdb database
随机推荐
微信小程序相关
Mongodb add delete modify query operation
在Python中创建文字云或标签云
简明 VIM 练级攻略
VirtualBox install centos7
性能压测时,并发压力增加,系统响应时间和吞吐量如何变化
When to write disk IO after one byte of write file
Js中常见的内存泄漏场景
框架-SPI四种模式+通用设备驱动实现-源码
How to deploy pytorch lightning model to production
如何将PyTorch Lightning模型部署到生产中
Python 列表的11个重要操作
Summary of interface test case ideas
佛萨奇forsage以太坊智能合约是什么?以太坊全球滑落是怎么回事
The interface testing tool eolinker makes post request
线程池运用不当的一次线上事故
(O) Analysis of service manager (1) BinderInternal.getContextObject
Five phases of API life cycle
给大家介绍下,这是我的流程图软件 —— draw.io
c++ opencv4.3 sift匹配