BubbleSort
作者:
CZL
,
2022-11-25 08:54:42
,
所有人可见
,
阅读 205
import java.util.*;
public class Main {
static int N = 100010;
static int a[] = new int[N];
static void BubbleSort(int n) {
for(int i = 0; i < n - 1; i ++ ) {
boolean flag = false;
for(int j = 0; j < n - i - 1; j ++ ) {
if(a[j] > a[j + 1]) {
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
flag = true;
}
}
if(!flag) return;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 0; i < n; i ++ ) {
a[i + 1] = sc.nextInt();
}
// qsort(1, n);
BubbleSort(n);
for(int i = 0; i < n; i ++ ) {
System.out.println(a[i + 1]);
}
}
}