常见的快速排序的交换方法代码没有错误吗

看到CSDN上很多帖子讲了快速排序的交换方法,有一个帖子的评论下面说了一种情况,也就是所有的数都比左基准值大,会造成排序错误,算了一下确实错了,但为什么大家都那么写呢。。
下面是找到的两个不同人的代码(都一样的)

img

img

然后是手算步骤

img

我写的就不一样:

#include<iostream>
using namespace std;
//交换函数swap
void swap1(int& a, int& b)
{
    int temp = a; a = b; b = temp;
}
//做一个把数组分两半的函数
int sortSecond(int A[], int low, int high)
{
    int P = A[high];//基数选择右边界
    while (low < high)
    {
        while (low < high && A[low] <= P)
            low++;//左边部分小的跳过
        if (low < high){
            swap1(A[low], A[high--]);//大的扔到后面并使右边界减一
        }
        while (low<high && A[high]>=P)
            high--;//右边大的跳过
        if (low < high) {
            swap1(A[low++], A[high]);//小的扔到前面并使左边界加一
        }
    }
    return low;//此时low=high
}
void fastSort(int A[], int low, int high)
{
    if (low > high) return;//递归结束条件 low>high
    int v = sortSecond(A, low, high);
    fastSort(A, low,  v - 1);//对左区间递归排序
    fastSort(A, v + 1, high);//对右区间递归排序
}
int main()
{
    int A[9] = {4,3,1,2,4,9,5,8,6};
    int len = sizeof(A) / sizeof(A[0]);
    cout << "排序前数组为:\t" << endl;
    for (int i = 0; i < len; i++)
    {
        cout << A[i] << " ";
    }
    cout << endl;
    fastSort(A, 0, len-1);//时间复杂度 平均情况O(nlogn),最坏情况O(n^2)
    cout << "快速排序后数组为:\t" << endl;
    for (int i = 0; i < len; i++)
    {
        cout << A[i] << " ";
    }
}