选择排序

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 星期一

posted on 2023-05-01 21:29  逆袭怪  阅读(13)  评论(0编辑  收藏  举报