package java02;
//Selection sort (Selection sort) is a simple and intuitive sorting algorithm.
//Its working principle is to select the smallest (or largest) element from the data elements to be sorted each time,
//store it at the beginning of the sequence, until all the data elements to be sorted are arranged.
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class selection sorting has popped out {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(new Date()) + " 郭子安的数字组选择排序");
Scanner in = new Scanner(System.in);
int a[] = new int[10];
int i, j, min, temp;
System.out.println("请输入10个整数:");
for (i = 0; i < 10; i++) {
int n = in.nextInt();
a[i] = n;
}
for (i = 0; i < 10; i++) {
min = i;
for (j = i + 1; j < 10; j++) {
if (a[j] < a[min]) {
min = j;
}
}
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
for (i = 0; i < 10; i++) {
System.out.printf(a[i] + " ");
}
System.out.println();
in.close();
}
}