@@ -1,11 +1,10 @@
1-<!DOCTYPE html> <html> <head> <title>quicksort.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="mergesort.html"> mergesort.js …
1+<!DOCTYPE html> <html> <head> <title>quicksort.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="insertionsort.html"> insertionsort.js …
2+<span class="s1">'use strict'</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>quick sort baby! </p>
23
34 <p>Chome's V8 uses this for Array.sort() for larger arrays (length 20ish or more)
4-much more to be found about quicksort here http://www.nczonline.net/blog/2012/11/27/computer-science-in-javascript-quicksort/</p> </td> <td class="code"> <div class="highlight"><pre><span class="s1">'use strict'</span><span class="p">;</span>
5-
6-<span class="kd">var</span> <span class="nx">swap</span><span class="p">,</span>
5+much more to be found about quicksort here http://www.nczonline.net/blog/2012/11/27/computer-science-in-javascript-quicksort/</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">swap</span><span class="p">,</span>
76 <span class="nx">partition</span><span class="p">,</span>
8- <span class="nx">quickSort</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>easy peasy swap function.</p>
7+ <span class="nx">quickSort</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>easy peasy swap function.</p>
98
109 <p>think 3 glasses, a red one with beer, a blue one with wine, and a white empty one.
1110 we want the beer in the blue glass and the wine in the red one.
@@ -15,7 +14,7 @@ pour the beer into the blue one.</p> </td> <td class="co
1514 <span class="kd">var</span> <span class="nx">tmp</span> <span class="o">=</span> <span class="nx">list</span><span class="p">[</span><span class="nx">first</span><span class="p">];</span>
1615 <span class="nx">list</span><span class="p">[</span><span class="nx">first</span><span class="p">]</span> <span class="o">=</span> <span class="nx">list</span><span class="p">[</span><span class="nx">second</span><span class="p">];</span>
1716 <span class="nx">list</span><span class="p">[</span><span class="nx">second</span><span class="p">]</span> <span class="o">=</span> <span class="nx">tmp</span><span class="p">;</span>
18-<span class="p">};</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>creates a smaller partition of the array</p>
17+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>creates a smaller partition of the array</p>
1918
2019 <p>starting with a middle point because if the array is sorted you'll get
2120 the worst possible performance if you choose the first or last elements.
@@ -46,7 +45,7 @@ return the left pointer so it can be used as the starting point for the next par
4645 <span class="p">}</span>
4746
4847 <span class="k">return</span> <span class="nx">left</span><span class="p">;</span>
49-<span class="p">};</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>Only operate on lists with 2 or more values.
48+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>Only operate on lists with 2 or more values.
5049 use default values for left and right if they are undefined (first run).
5150 partition the array.
5251 if the left pointer can still be moved right towards the index, call quicksort again in that direction.
@@ -70,8 +69,11 @@ if the right pointer can be moved left, call quicksort from the current index.</
7069 <span class="p">}</span>
7170
7271 <span class="k">return</span> <span class="nx">list</span><span class="p">;</span>
73-<span class="p">};</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>can this be used for sorting lists of strings alphabetically ?</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> …
72+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p>module jargon</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="p">(</span><span class="nx">module</span> <span class="o">& …
7473 <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span><span class="p">.</span><span class="nx">quickSort</span> <span class="o">=</span> <span class="nx">quickSort</span><span class="p">;</span>
74+<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
75+ <span class="nb">window</span><span class="p">.</span><span class="nx">algos</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">algos</span> <span class="o">||</span> <span class="p">{};</span>
76+ <span class="nb">window</span><span class="p">.</span><span class="nx">algos</span><span class="p">.</span><span class="nx">quickSort</span> <span class="o">=</span> <span class="nx">quickSort</span><span class="p">;</span>
7577 <span class="p">}</span>
7678
7779 </pre></div> </td> </tr> </tbody> </table> </div> </body> </html>