选择排序
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner (System.in);
int n = sc.nextInt();
int [] q = new int[n];
for (int i = 0; i < n; i ++)
q[i] = sc.nextInt();
for (int i = 0; i < n; i ++)
for (int j = i + 1; j < n; j ++)
if (q[j] < q[i]){
int t = q[i];
q[i] = q[j];
q[j] = t;
}
for (int i = 0; i< n; i ++)
System.out.printf("%d ", q[i]);
}
}
2023-05-01 21:28:57 星期一
本文来自博客园,作者:逆袭怪,转载请注明原文链接:https://www.cnblogs.com/fghjktgbijn/p/17367034.html