Auto commit

This commit is contained in:
smallkun 2025-04-03 10:23:32 +08:00
parent 712b37490c
commit 39672f95cb

View File

@ -38,6 +38,41 @@ int main(){
### 选择排序
```c
#include <stdio.h>
void selectSort(int *a, int n, int flag){
int i, j, t;
for(i=0;i<n-1;i++){
for(j=i;j<n;j++){
if(flag > 0?a[i] > a[j]:a[i] < a[j]){
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
}
void printArray(int *a, int n){
int i;
for(i=0;i<n;i++){
printf("%d ", a[i]);
}
printf("\n");
}
int main(){
int a[] = {100, 1, 3, 2, 9, -1, 20, 30, 10, 50};
int n = sizeof(a)/4;
selectSort(a, n, 0);
printArray(a, n);
return 0;
}
```
### 插入排序