#include <stdio.h>
#include <malloc.h>
void bubbleSort(int* sortArr,int len);
int main(void) {
// int num[]={3,4,2,1,5,8,7,9,6};
int counts;
int i=0;
printf("input your num numbers:\n");
scanf("%d",&counts);
int *num = (int *)malloc(counts*sizeof(int));
for(int j=0;j<counts;j++){
scanf("%d",num+j);
}
int len=counts;
bubbleSort(num,len);
for(i;i<len;i++){
printf("%d\n",*(num+i));
}
return 0;
}
void bubbleSort(int *sortArr,int len){
int temp;
for(int i=0;i<len;i++){
for(int j=0;j<len-i-1;j++){
if(sortArr[j]>sortArr[j+1]){
temp = sortArr[j];
sortArr[j] = sortArr[j+1];
sortArr[j+1] = temp;
}
}
}
}
数据结构--冒泡排序(C语言)
最新推荐文章于 2024-01-14 20:37:23 发布