我说的对吗?这两种算法都是将你的结构递归地分成两部分,然后按正确顺序构建结构,是这样吗?
那么,它们有什么区别呢?
编辑:我找到了实现快速排序中分区的以下算法,但我真的不明白它是如何工作的,特别是使用 (hi + low) >>> 1
作为参数的交换行!有人能理解这个吗?
private static int partition( int[] items, int lo, int hi )
{
int destination = lo;
swop( items, (hi + lo) >>> 1, hi );
// The pivot is now stored in items[ hi ].
for (int index = lo; index != hi; index ++)
{
if (items[ hi ] >= items[ index ])
{
// Move current item to start.
swop( items, destination, index );
destination ++;
}
// items[ i ] <= items[ hi ] if lo <= i < destination.
// items[ i ] > items[ hi ] if destination <= i <= index.
}
// items[ i ] <= items[ hi ] if lo <= i < destination.
// items[ i ] > items[ hi ] if destination <= i < hi.
swop( items, destination, hi );
// items[ i ] <= items[ destination ] if lo <= i <= destination.
// items[ i ] > items[ destination ] if destination < i <= hi.
return destination;
}