SelectSort 选择排序
//SelectSort (( O(n²)))
public class TestSelectSort { public int[] selectSortArray(int[] arr){
int min_index; for(int i = 0; i <arr.length - 1; i ++){
min_index = i;
for(int j = i + 1; j < arr.length; j ++){
if(arr[j] < min_index){
min_index = j;
}
if(min_index != i){
int temp;
temp = arr[i];
arr[i] = arr[min_index];
arr[min_index] = temp;
}
}
} return arr;
} public static void main(String[] args) {
int[] arr = {6,2,4,1,5,9};
TestSelectSort test = new TestSelectSort();
test.selectSortArray(arr); for(int i = 0 ; i < arr.length; i ++){
System.out.println(arr[i]);
}
} }
选择排序——每次最小/大排在相应的位置
SelectSort 选择排序的更多相关文章
- 排序算法ONE:选择排序SelectSort
/** *选择排序: * 对冒泡排序的一个改进 * 进行一趟排序时,不用每一次都交换,只需要把最大的标示记下 * 然后再进行一次交换 */ public class SelectSort { /** ...
- Java基础(46):选择排序的Java封装(完整可运行)
1 package lsg.ap.select; import java.util.Random; public class SelectSort { //选择排序 /** *@author: 梁山广 ...
- [算法] 选择排序 Selection sort
选择排序(Selection sort)是一种简单直观的排序算法.它的工作原理如下.首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然 ...
- 选择排序算法Java实现
一. 算法描述 选择排序:比如在一个长度为N的无序数组中,在第一趟遍历N个数据,找出其中最小的数值与第一个元素交换,第二趟遍历剩下的N-1个数据,找出其中最小的数值与第二个元素交换......第N-1 ...
- golang数据结构之选择排序
//SelectSort 选择排序 func SelectSort(arr *[]int) { ; i < len(arr); i++ { tmp := arr[i] index := i ; ...
- 排序算法-选择排序(Java)
package com.rao.linkList; import java.util.Arrays; /** * @author Srao * @className SelectSort * @dat ...
- 选择排序SelectSort
/** * * @author Administrator * 功能:选择排序法 */ package com.test1; import java.util.Calendar; public cla ...
- 排序之选择排序(SelectSort)
package com.sort; /* * 选择排序 * 把第一位与其他数进行比较,这样每轮比较都会出现一个最大值或最小值 * 根据需要让升序或降序排列 */ public class Select ...
- C#数据结构与算法系列(十九):选择排序算法(SelectSort)
1.介绍 选择排序算法属于内部排序算法,是从欲排序的数据中,按指定的规则选出某一元素,再依规定交换位置达到排序的目的 时间复杂度:O(n^2) 双层for 2.思想 选择排序(select sorti ...
随机推荐
- HTML获取用户输入的几种玩法
input标签 input是一个自闭和标签,可以获得用户的输入 form标签 form标签是用来进行表单提交用的,它把用户的输入内容提交到服务器. 一个注册页面的例子 <!DOCTYPE htm ...
- 1030 - Image Is Everything (贪心)
Your new company is building a robot that can hold small lightweight objects. The robot will have th ...
- JavaScript新手学习笔记4——我记不住的几个坑:短路逻辑、按值传递、声明提前
1.短路逻辑 逻辑运算中,如果前一个条件已经可以得出最终结论,则后续所有条件不再执行!这里的逻辑运算指的是逻辑与和逻辑或. 我们要理解逻辑与是两个条件都为真的时候,才为真,如果第一个就是假的,那么后面 ...
- 【C#通用类】日志记录类
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- Nyoj 43 24 Point game 【DFS】
24 Point game 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描写叙述 There is a game which is called 24 Point game ...
- windows 7 SDK和DDK下载地址
查个小资料,得到地址,顺便记录一下. Windows Driver Kit Version 7.1.0 http://www.microsoft.com/downloads/details.aspx? ...
- [Redux] React Todo List Example (Adding a Todo)
Learn how to create a React todo list application using the reducers we wrote before. /** * A reduce ...
- Tomcat全攻略
内容: 一:简单介绍 二:安装及配置 三:应用 四:综述 參考资料 关于作者 相关内容: TCP/IP 介绍 TCP/IP 介绍 !== End Related dW Content Area --& ...
- 小学生之手(01)之 "for循环"
---恢复内容开始--- 咳咳咳!第一次要写这种东西,要是有不足的地方,请见谅!!!并且感觉在这班门弄斧是不是有点托大了.一向擅长低调的我,在’被逼无奈‘之下,要嚣张一下了......(此处省略500 ...
- C# Interface显式实现和隐式实现
c#中对接口的实现方式有两种:隐式实现和显式实现,之前一直没仔细看过,今天查了些资料,在这里整理一下. 隐式实现的例子 interface IChinese { string Speak(); } p ...