我知道我们可以通过删除超过 1 个递归调用并将其减少到一次单个递归调用来利用尾递归来优化快速排序:-
void quickSort(int arr[], int low, int high)
{
if (low < high)
{
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
void quickSort(int arr[], int low, int high)
{
start:
if (low < high)
{
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
low = pi+1;
high = high;
goto start;
}
}
但是我们可以用尾递归优化随机快速排序吗?