标签:
#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;
}
}
}
}
标签:
原文地址:http://www.cnblogs.com/caocx/p/5798465.html