algorithm-php
algorithm-php copied to clipboard
快速排序算法中,和看到的c的实现不一样
在一本算法结构的书中,介绍的快速排序,每一趟排序都会去交换。 但这里的好像只是找到了比基准值大的和小的两个数组,然后最后再去合并。 书上的c的实现: `int Quick(List R, int low, int high) { x=R[low];
while(low<high)
{
while((low<high) && R[high].key >= x.key)
{
high --;
}
R[low] = R[high];
while(low<high && R[low].key <= x.key)
{
low++;
}
R[high] = R[low];
}
R[low] = x;
return low;
}
void QuickSort(List R, int low, int high) { if (low < high) { temp = Quick(R, low, high); QuickSort(R, low, temp - 1); QuickSort(R, temp + 1, high); } }`