当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 进程 线程 协程
- experiment
- 如果把编程语言当武功绝学!C++是九阴真经,那程序员呢?
- [开源] .Net 使用 ORM 访问 华为GaussDB数据库
- Solution to the problem of offline connection between ADB and mobile phone
- (O)ServiceManager分析(一)之BinderInternal.getContextObject
- 前后端分离跨域问题解决方案
- Iptables from introduction to mastery
- TypeScript(1-2-2)
- Tencent: Although Ali's Taichung is good, it is not omnipotent!
猜你喜欢
C / C + + knowledge sharing: function pointer and pointer function, can you understand after reading this article?
Wechat applet related
Django之简易用户系统(3)
Flink's sink: a preliminary study
Solution to cross domain problem of front end separation
[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!
Simulink中封装子系统
Not a programmer, code can't be too ugly! The official writing standard of Python: pep8 everyone should know
experiment
Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
随机推荐
jsliang 求职系列 - 07 - Promise
npm install 无响应解决方案
苏州游记
I used Python to find out all the people who deleted my wechat and deleted them automatically
在Python中创建文字云或标签云
[开源] .Net 使用 ORM 访问 华为GaussDB数据库
Summary of interface test case ideas
Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19
Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
Mongodb add delete modify query operation
Talk about go code coverage technology and best practices
进程 线程 协程
佛萨奇forsage以太坊智能合约是什么?以太坊全球滑落是怎么回事
Django之简易用户系统(3)
Express framework
SQL quick query
Flink的sink实战之一:初探
为什么需要使用API管理平台
net.sf.json.JSONObject对时间戳的格式化处理
opencv 解决ippicv下载失败问题ippicv_2019_lnx_intel64_general_20180723.tgz离线下载