BubbleSort冒泡排序

#include <stdio.h>
void BubbleSort(int *a,int n);
int main(void){
int arr[10] = {2,4,6,8,0,1,3,5,7,9};
int k;
for(k=0;k<10;k++){
if(k==9)
printf("%d\n",arr[k]);
else
printf("%d,",arr[k]);
}
BubbleSort(arr,10);
for(k=0;k<10;k++){
if(k==9)
printf("%d\n",arr[k]);
else
printf("%d,",arr[k]);
}
return 0;
}
void BubbleSort(int *a,int n){
int i,j,t;
for(i=0;i<n-1;i++){
for(j = 0;j<n-i-1;j++){
if(a[j]>a[j+1]){
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
}

posted @ 2016-08-23 11:06  caocx  阅读(191)  评论(0编辑  收藏  举报