l が返される正しい値であり、 l=lowの初期化がどのように行われるかを不変式からどのように理解できますか。h =高い; 不変式を確立しますか?
/* 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;
}