1 /*冒泡排序的实现*/ 2 #include<stdio.h> 3 4 void BubbleSort(int *a, int l) 5 { 6 int tmp; 7 for(int i = 0; i < l; i++) 8 { 9 for(int j=i+1; j<l; j++) 10 { 11 if(a[j]<a[i]) 12 { 13 tmp = a[j]; 14 a[j] = a[i]; 15 a[i] = tmp; 16 } 17 } 18 } 19 } 20 21 int main(int argc, char const *argv[]) 22 { 23 int a[] = {27,13,76,97,65,38,49}; 24 25 int l = sizeof(a)/sizeof(a[1]); 26 BubbleSort(a,l); 27 28 for(int k = 0; k<l; k++) 29 { 30 printf("%d ",a[k]); 31 } 32 printf(" "); 33 return 0; 34 }