add select-sort

This commit is contained in:
2012-09-12 20:11:25 +08:00
parent 9d8eda44c4
commit 8e30a2448d
5 changed files with 76 additions and 0 deletions
+2
View File
@@ -1 +1,3 @@
.metadata/
*/bin
*/settings
+6
View File
@@ -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>
+17
View File
@@ -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;
}
}
}
}