39 lines
740 B
C
39 lines
740 B
C
#include <stdio.h>
|
|
|
|
void bubbleSort(int a[], int n);
|
|
|
|
//输出数组中所有元素
|
|
void outputData(int data[], int elementCount);
|
|
|
|
int main() {
|
|
int n, i, num[10010];
|
|
|
|
scanf("%d", &n);
|
|
for (i = 0; i < n; i++)
|
|
scanf("%d", &num[i]);
|
|
bubbleSort(num, n);
|
|
outputData(num, n);
|
|
return 0;
|
|
}
|
|
|
|
/* 请在这里填写答案 */
|
|
void bubbleSort(int a[], int n) {
|
|
int tmp;
|
|
for (int i = 0; i < n - 1; i++) {
|
|
for (int j = 0; j < n - 1; j++) {
|
|
if (a[j] > a[j + 1]) {
|
|
tmp = a[j];
|
|
a[j] = a[j + 1];
|
|
a[j + 1] = tmp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void outputData(int data[], int elementCount) {
|
|
for (int i = 0; i < elementCount - 1; i++) {
|
|
printf("%d ", data[i]);
|
|
}
|
|
printf("%d\n", data[elementCount - 1]);
|
|
}
|