标签:
1 void BubbleSort(int unsort[],const int count) 2 { 3 for (int i = 0; i < count;i++) 4 { 5 for (int j = 0;j<i;j++) 6 { 7 int temp; 8 if (unsort[j]>unsort[j+1]) 9 { 10 temp = unsort[j]; 11 unsort[j] = unsort[j + 1]; 12 unsort[j + 1] = temp; 13 } 14 } 15 } 16 }
测试
1 int main() 2 { 3 int unsort[] = {2,5,7,4,6,9}; 4 BubbleSort(unsort, 6); 5 for (int i = 0; i < 6;i++) 6 { 7 printf("%d\r",unsort[i]); 8 } 9 return 0; 10 }
标签:
原文地址:http://www.cnblogs.com/jingliming/p/4330987.html