User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
algorithm:insertion_sort [2014/05/14 23:16]
will
algorithm:insertion_sort [2015/02/02 08:28] (current)
Line 1: Line 1:
-[algorithm ​Insertion sort]+======= λ Insertion sort ======
  
-====== Algorithm ======+<​nowiki>​ 
 +======= Algorithm ​=======
 <syntax js> <syntax js>
 function insertSort(a) { function insertSort(a) {
Line 13: Line 14:
 </​syntax>​ </​syntax>​
  
-====== Support ======+======= Support ​=======
 <syntax js> <syntax js>
 function swap(a, i, j) { function swap(a, i, j) {
Line 26: Line 27:
 </​syntax>​ </​syntax>​
  
-====== Options ======+======= Tests ======= 
 +<syntax js> 
 +</​syntax>​ 
 + 
 +======= Options ​=======
 <syntax js> <syntax js>
 { {
 +    "​title":​ "​Insertion sort",
     "​height":​ "​270px"​     "​height":​ "​270px"​
 } }
 </​syntax>​ </​syntax>​
  
-====== Visualisation ======+======= Visualisation ​=======
 <syntax html> <syntax html>
 <​html>​ <​html>​
Line 47: Line 53:
 } }
  
-function args() { +function args(forCloning) { 
-    return graph.array;​+    return ​forCloning? graph.getClonableArray() : graph.array;​
 } }
     ​     ​
-var oldI;+var lastUpdateDate = 0;
  
 function update(n, x, isRunning, duration, prev) { function update(n, x, isRunning, duration, prev) {
Line 58: Line 64:
     }     }
     if (x) {     if (x) {
-        graph.drawGraph(duration);​+        graph.drawGraph(duration, 0);
         ​         ​
         var sortedN = x.lookupInScope("​sortedN"​);​         var sortedN = x.lookupInScope("​sortedN"​);​
Line 68: Line 74:
     }     }
         bars.classed("​sorted",​ function(d, i) {return sortedN && i<​sortedN});​         bars.classed("​sorted",​ function(d, i) {return sortedN && i<​sortedN});​
-        if (idx !== oldI) {+        ​ 
 +        // Unfortunate use of line numbers to highlight index being moved. 
 +        ​if (!n || (n.lineno !== 4 && n.lineno !== 5)){ 
 +        bars.classed("​index",​ false); 
 +        } 
 +        else if (n.lineno === 5) {
             bars.classed("​index",​ function(d, i) {return i===idx});             bars.classed("​index",​ function(d, i) {return i===idx});
-            oldI = idx; 
         }         }
     }     }
Line 87: Line 97:
 </​html>​ </​html>​
 </​syntax>​ </​syntax>​
 +</​nowiki>​
algorithm/insertion_sort.1400134586.txt.gz · Last modified: 2015/02/02 08:23 (external edit)