今天是我最熟悉的冒泡法。。
int bubble_sort(int * arr, unsigned int arrLength) { unsigned int iLoop = 0; unsigned int jLoop = 0; int tempChange = 0; if(arr == NULL) { return -1; } for(iLoop = 0; iLoop < arrLength; ++iLoop) { for(jLoop = arrLength - 1; jLoop > iLoop; --jLoop) { if(arr[jLoop] < arr[jLoop - 1]) { tempChange = arr[jLoop]; arr[jLoop] = arr[jLoop - 1]; arr[jLoop - 1] = tempChange; } } } return 0; }