当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 腾讯:阿里的大中台虽好,但也不是万能的!
- write文件一个字节后何时发起写磁盘IO
- Express框架
- 接口测试用例思路总结
- (O)ServiceManager分析(一)之BinderInternal.getContextObject
- One minute comprehensive understanding of forsage smart contract global shared Ethereum matrix plan
- Framework - SPI four modes + general device driver implementation - source code
- 微信小程序相关
- 在Python中创建文字云或标签云
- 实验
猜你喜欢
随机推荐
第二章编程练习
CountDownLatch 瞬间炸裂!同基于 AQS,凭什么 CyclicBarrier 可以这么秀?
(O)ServiceManager分析(一)之BinderInternal.getContextObject
【杂谈】JS相关的线程模型整理
How much disk IO does a byte of read file actually take place?
SQL 速查
write文件一个字节后何时发起写磁盘IO
C + + opencv4.3 sift matching
[open source]. Net uses ORM to access Huawei gaussdb database
LiteOS-消息队列
Use markdown
Solution to the problem of offline connection between ADB and mobile phone
Opencv solves the problem of ippicv download failure_ 2019_ lnx_ intel64_ general_ 20180723.tgz offline Download
Hello world of rabbitmq
WordPress网站程序和数据库定时备份到七牛云图文教程
Not a programmer, code can't be too ugly! The official writing standard of Python: pep8 everyone should know
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
Suffix expression to infix expression
Application of four ergodic square of binary tree
How does the system response time and throughput change with the increase of concurrency pressure during performance pressure testing





