- void BubbleSort(int a[], int size)
- {
- int lastSwapPos = 0,lastSwapPosTemp = 0;
- for (int i = 0; i < size - 1; i++)
- {
- lastSwapPos = lastSwapPosTemp;
- for (int j = size - 1; j >lastSwapPos; j--)
- {
- if (a[j - 1] > a[j])
- {
- int temp = a[j - 1];
- a[j - 1] = a[j];
- a[j] = temp;
- lastSwapPosTemp = j;
- }
- }
- if (lastSwapPos == lastSwapPosTemp)
- break;
- }
- }
改进的冒泡排序算法
最新推荐文章于 2023-12-02 20:56:03 发布