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:queue_list-based [2014/07/26 23:42]
will
algorithm:queue_list-based [2016/04/03 00:21] (current)
will Updated tests.
Line 1: Line 1:
-[algorithm Queue_list-based]+======= λ Queue list-based ​======
  
-====== Algorithm ======+<​nowiki>​ 
 +======= Algorithm ​=======
 <syntax js> <syntax js>
 function Queue() { function Queue() {
Line 34: Line 35:
             }             }
         }         }
-        return popped;+        return popped? popped.data : null;
     }     }
-} +}</​syntax>​
-</​syntax>​+
  
-====== Support ======+======= Support ​=======
 <syntax js> <syntax js>
 // Initial starting queue. // Initial starting queue.
Line 59: Line 59:
 </​syntax>​ </​syntax>​
  
-====== Options ======+======= Tests ======= 
 +<syntax js> 
 +function testA() { 
 +    var q = new Queue(); 
 +    q.enqueue(1);​ 
 +    q.enqueue(2);​ 
 +    q.enqueue(3);​ 
 +     
 +    assert(q.dequeue() === 1); 
 +    assert(q.dequeue() === 2); 
 +    assert(q.dequeue() === 3); 
 +    assert(q.dequeue() === null, "End of queue."​);​ 
 +
 + 
 +function testB() { 
 +    var q = new Queue(); 
 +    q.enqueue(1);​ 
 +    q.enqueue(2);​ 
 +     
 +    assert(q.dequeue() === 1); 
 +     
 +    q.enqueue(3);​ 
 +    q.enqueue(4);​ 
 +     
 +    assert(q.dequeue() === 2); 
 +     
 +    q.enqueue(5);​ 
 +     
 +    assert(q.dequeue() === 3); 
 +    assert(q.dequeue() === 4); 
 +    assert(q.dequeue() === 5); 
 +    assert(q.dequeue() === null, "End of queue."​);​ 
 +}</​syntax>​ 
 + 
 +======= Options ​=======
 <syntax js> <syntax js>
 { {
 +    "​title":​ "Queue list-based",​
     "​height":​ "​450px",​     "​height":​ "​450px",​
     "​preRunSource":​ true,     "​preRunSource":​ true,
Line 68: Line 103:
 </​syntax>​ </​syntax>​
  
-====== Visualisation ======+======= Visualisation ​=======
 <syntax html> <syntax html>
 <​html>​ <​html>​
Line 240: Line 275:
 </​body>​ </​body>​
 </​html></​syntax>​ </​html></​syntax>​
 +</​nowiki>​
algorithm/queue_list-based.1406443358.txt.gz · Last modified: 2015/02/02 08:23 (external edit)