test commit with vscode
This commit is contained in:
parent
92c01818fd
commit
ceb39acadb
38
pset10/sort.c
Normal file
38
pset10/sort.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
#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]);
|
||||
}
|
Loading…
Reference in a new issue