快速排序还有一个while没执行 直接swap 感觉不对 但是还真得加上 不是按照顺序执行的么 low还没加就直接swap

#include
void Swap(int arr[], int low, int high)
{
int temp;
temp = arr[low];
arr[low] = arr[high];
arr[high] = temp;
}

int Partition(int arr[], int low, int high)
{
int base = arr[low];
while(low < high)
{
while(low < high && arr[high] >= base)
{
high --;
}
Swap(arr, low, high);
while(low < high && arr[low] <= base)
{
low ++;
}
Swap(arr, low, high);
}
return low;
}

void QuickSort(int arr[], int low, int high)
{
if(low < high)
{
int base = Partition(arr, low, high);
QuickSort(arr, low, base - 1);
QuickSort(arr, base + 1, high);
}
}

int main()
{
int n;
scanf("%d\n",&n);
int arr[n];
int i , j;
for(i = 0; i < n; i ++)
{
scanf("%d",&arr[i]);
}
printf("\n");
QuickSort(arr, 0, n-1);
for(j = 0; j < n; j ++)
{
printf("%4d",arr[j]);
}
return 0;
}

感觉代码没问题,你换一组数据试试

您说的这两种方法都是可行的,您贴的代码是标准的快速排序代码,如果等两个while执行完再swap,在执行swap之前,需要判断一下:if(low<hight)