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/07/05 22:47]
will
algorithm:insertion_sort [2015/02/02 08:28] (current)
Line 1: Line 1:
-====== Insertion ​Sort ====== +======= λ Insertion ​sort ======
-[algorithm Insertion sort]+
  
-====== Algorithm ======+<​nowiki>​ 
 +======= Algorithm ​=======
 <syntax js> <syntax js>
 function insertSort(a) { function insertSort(a) {
Line 14: Line 14:
 </​syntax>​ </​syntax>​
  
-====== Support ======+======= Support ​=======
 <syntax js> <syntax js>
 function swap(a, i, j) { function swap(a, i, j) {
Line 27: 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 52: Line 57:
 } }
     ​     ​
-var oldI;+var lastUpdateDate = 0;
  
 function update(n, x, isRunning, duration, prev) { function update(n, x, isRunning, duration, prev) {
Line 59: Line 64:
     }     }
     if (x) {     if (x) {
-        graph.drawGraph(duration);​+        graph.drawGraph(duration, 0);
         ​         ​
         var sortedN = x.lookupInScope("​sortedN"​);​         var sortedN = x.lookupInScope("​sortedN"​);​
Line 69: 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 88: Line 97:
 </​html>​ </​html>​
 </​syntax>​ </​syntax>​
 +</​nowiki>​
algorithm/insertion_sort.1404625644.txt.gz · Last modified: 2015/02/02 08:23 (external edit)