Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Check wikipedia, there is a little example with a bit smaller list of inplace quicksort <a href="http://en.wikipedia.org/wiki/Quicksort" rel="nofollow">http://en.wikipedia.org/wiki/Quicksort</a></p> <p>With your example the idea is to partition</p> <pre><code>{15, 19, 34, 41, 27, 13, 9, 11, 44} </code></pre> <p>into</p> <pre><code>{13, 9, 11 -- 15 -- 19, 34, 41, 27, 44} </code></pre> <p>So first we move pivot to the end</p> <pre><code>Swap 44, and 15 {44, 19, 34, 41, 27, 13, 9, 11, 15} ^ ^ Than check 44, its larger than pivot, so swap with one one before last... {11, 19, 34, 41, 27, 13, 9, 44, 15} ^ ^ than check element at some position as last one was larger than pivot. 9 &lt; 15, so proceed to the next, 19 &gt; 15 =&gt; swap {11, 9, 34, 41, 27, 13, 19, 44, 15} ^ ^ swap again {11, 9, 13, 41, 27, 34, 19, 44, 15} ^ ^ next {11, 9, 13, 41, 27, 34, 19, 44, 15} ^ ^ and second last swap {11, 9, 13, 27, 41, 34, 19, 44, 15} ^ Now as forward and backward indices reached each other, we swap pivot into right position {11, 9, 13, 15, 41, 34, 19, 44, 27} </code></pre> <p>And we got partitioned set. Items less than 15 at the beginning, than pivot = 15, and then greater elements.</p> <p>EDIT: algorithm described in wikipedia article is a bit different:</p> <pre><code>Legend: ^ = storeindex # = i {44, 19, 34, 41, 27, 13, 9, 11, 15} ^# {44, 19, 34, 41, 27, 13, 9, 11, 15} ^ # ... until ... {44, 19, 34, 41, 27, 13, 9, 11, 15} ^ # {13, 19, 34, 41, 27, 44, 9, 11, 15} ^ # {13, 9, 34, 41, 27, 44, 19, 11, 15} ^ # {13, 9, 11, 41, 27, 44, 19, 34, 15} ^ # {13, 9, 11, 15, 27, 44, 19, 34, 41} ^- pivot </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload