java选择排序SelectSort的代码和使用(包含清晰完成过程)
来源:互联网 发布:淘宝达人直播怎么开通 编辑:程序博客网 时间:2024/06/07 09:39
public class SelectSort {public static void sort(int array[]) {int count=0;int minIndex = 0;int temp = 0;for (int i = 0; i < array.length; i++) {minIndex = i;// 无序区的最小数据数组下标for (int j = i + 1; j < array.length; j++) {// 在无序区中找到最小数据并保存其数组下标if (array[j] < array[minIndex]) {minIndex = j;}}if (minIndex != i) {// 如果不是无序区的最小值位置不是默认的第一个数据,则交换之。System.out.print("第"+count+"趟:");for(int n=0;n<array.length;n++)System.out.print(array[n]+" ");System.out.println("\n");temp = array[i];array[i] = array[minIndex];array[minIndex] = temp;count++;}}System.out.print("第"+count+"趟:");for (int i = 0; i < array.length; i++)System.out.print(array[i] + " ");}public static void main(String args[]) {long startTime=System.nanoTime(); //获取开始时间int arr[]=new int[25];for(int r=0;r<arr.length;r++){arr[r]=(int)(Math.random()*100+1);//100之内的随机数}sort(arr);long endTime=System.nanoTime(); //获取结束时间System.out.println("\n");System.out.println("-------程序运行时间: "+(endTime-startTime)+"ns-------");}}
0 0
- java选择排序SelectSort的代码和使用(包含清晰完成过程)
- java快速排序QuickSort的代码和使用(包含清晰完成过程)
- java插入排序InsertSort的代码和使用(包含清晰完成过程)
- java交换排序ExchangeSort的代码和使用(包含清晰完成过程)
- java冒泡排序BubbleSort的代码和使用(包含清晰完成过程)
- Java--选择排序(SelectSort)
- [算法 java] 选择排序selectSort
- 选择排序及C++/java代码实现(SelectSort)
- 数据算法之选择排序(selectSort)的Java实现
- 选择排序(Selectsort)之Java实现
- 选择排序(Selectsort)之Java实现
- 选择排序:selectSort
- selectSort - 选择排序
- SelectSort,选择排序
- 选择排序SelectSort
- 选择排序-selectSort
- 选择排序--SelectSort
- 选择排序-selectsort
- iOS中的round/ceil/floorf函数略解
- 我该如何在这个行业存活下去
- SpringMVC集成Tiles2
- 广播(Broadcast内部机制讲解)
- Activity启动模式 及 Intent Flags 与 栈 的关联分析
- java选择排序SelectSort的代码和使用(包含清晰完成过程)
- 即时通讯云服务·融云开发者沙龙活动(10月份)公告
- 判断素数系列
- box2d b2Filter 碰撞过滤
- host 域名
- 【产品设计】互联网思维概念
- app从appstore上下载下来后崩溃。但是我手机曾用xcode装过,从appstore上下载就没有问题
- C#学习之值类型与引用类型
- vxworks VS linux