<?xml version="1.0" encoding='utf-8'?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Quickselect - Page 8 - Wikipedia">
<p>
<a accesskey="1" href="page.php?w=Quickselect&amp;p=7">1.Previous</a><br />
<a accesskey="3" href="page.php?w=Quickselect&amp;p=9">3.Next</a>
</p>
<p>with a loop:</p>

<p> <b>function</b> select(list, left, right, k) <b>is</b>     <b>loop</b>         <b>if</b> left = right <b>then</b>             <b>return</b> list[left]         pivotIndex := ...     // select pivotIndex between left and right         pivotIndex := partition(list, left, right, pivotIndex)         <b>if</b> k = pivotIndex <b>then</b>             <b>return</b> list[k]         <b>else if</b> k < pivotIndex <b>then             right := pivotIndex - 1         <b>else</b>             left := pivotIndex + 1This <code>select</code> function works only with the <a href="page.php?w=Quicksort">Lomuto partition scheme</a>. This is because <code>select</code> assumes that the return value from partition is the position of the pivot. This is true for the <a href="page.php?w=Quicksort">Lomuto partition scheme</a>, but not for the <a href="page.php?w=Quicksort">Hoare's partition scheme</a>. In Hoare's scheme, the return value is the last index of the "left" partition, and the pivot is not guaranteed to be "in between" the partitions.</></p><p>
<a accesskey="1" href="page.php?w=Quickselect&amp;p=7">1.Previous</a><br />
<a accesskey="3" href="page.php?w=Quickselect&amp;p=9">3.Next</a>
</p>

<do type="prev" label="Search">
        <go href="search.wml"/>
</do>

</card>
</wml>
