mirror of
https://github.com/wahyd4/java-sorting.git
synced 2026-08-09 04:46:05 +10:00
add select-sort
This commit is contained in:
@@ -1 +1,3 @@
|
||||
.metadata/
|
||||
*/bin
|
||||
*/settings
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>SelectSort</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.toozhao.sort;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Junv
|
||||
*
|
||||
*/
|
||||
public class SelectSort {
|
||||
// 定义需要排序的数
|
||||
private static int[] array = { 10, 50, 8, 29, 30, 17, 12, 40, 32, 7, 4, 22 };
|
||||
|
||||
public static void main(String args[]) {
|
||||
sort(array);
|
||||
for (int flag : array) {
|
||||
System.out.print(flag + " ");
|
||||
}
|
||||
}
|
||||
|
||||
public static void sort(int[] data) {
|
||||
// 外层循环一次,找到i to (data.length-1)这个数组中最小的一个数。
|
||||
for (int i = 0; i < (data.length - 1); i++) {
|
||||
// temp用来标注值最小的那个数。
|
||||
int temp = i;
|
||||
for (int j = i + 1; j < data.length; j++) {
|
||||
// 将temp 始终标记为最小那个数。
|
||||
if (data[j] < data[temp]) {
|
||||
temp = j;
|
||||
}
|
||||
}
|
||||
// 如果i != temp 说明,最小那个数为data[temp],则交换。
|
||||
if (i != temp) {
|
||||
int t = data[i];
|
||||
data[i] = data[temp];
|
||||
data[temp] = t;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user