C语言实现快排双向扫描代码的问题


#include<stdio.h>
#include<math.h>
#include<time.h>
void swap(int a[],int p,int q)                        //数组元素交换函数
{
    int temp=a[p];
    a[p]=a[q];
    a[q]=temp;
}
int  partition2(int a[],int p, int r)                //双向扫描分区法
{
    int pivot=a[p];
    int left=p+1;
    int right=r;
    while(left>right)
    {
        while(left>right&&a[left]<=pivot)
        {
            left++;
        }
        while(left>right&&a[right]>pivot)
        {
            right--;
        }
        if(left>right)
        {
            swap(a,left,right);
        }
    }
        swap(a,p,right);
        return right;
}
void QuickSort(int a[],int p,int r)
{
    if(p<r)
    {
        int q=partition2(a,p,r);
        QuickSort(a,p,q-1);                        //向左做递归
        QuickSort(a,q+1,r);                        //向右做递归
    }

}
void main()
{
    int arr[10];
    srand(time(NULL));
    for(int i=0;i<=9;i++)
    {
        arr[i]=rand()%20;
    }
    for(int i=0;i<=9;i++)
    {
        printf("%d\t",arr[i]);
    }
    printf("\n");
    QuickSort(arr,0,9);
    for(int i=0;i<=9;i++)
    {
        printf("%d\t",arr[i]);
    }
    
}

麻烦看看为什么这段代码无法实现排序?

img