我如何从不变量中理解 l 是要返回的正确值以及如何初始化l=low ; 和h=high ; 建立不变量?
/* invariant
* low <= l <= h <= high
* In region for indexes i with low <= i < end:
* elements are as originally, but rearranged.
* if i < l then arr[i] < x
* if i >= h then arr[i] >= x
* Elements outside region are unchanged.
*/
private static int partition(int[] arr, int low, int high, int x)
{
int l = low;
int h = high;
while (l<h)
{
if (arr[l] < x)
l =l +1;
else
{
int x = arr[l];
arr[l] = arr[h-1];
arr[h-1] = x
h = h-1;
}
}
return l;
}