Sample Queue Functions

by zazagalaxy

HTML

<input type="button" value="Go" onclick="alert(doFun(q));" />

JavaScript

function doFun(q) {
  // Enqueue is equivalent to push, Dequeue is equivalent to shift
  var s = []; 
while(q.length != 0) {s.push(q.shift());}
while(s.length != 0) {q.push(s.pop());}
  return q;
}