Javascript Data Structure Queue via function
function Queue() { let items = []; this.enqueue = function(element){ items.push(element);/*www .ja v a 2s . co m*/ }; this.dequeue = function(){ return items.shift(); }; this.front = function(){ return items[0]; }; this.isEmpty = function(){ return items.length == 0; }; this.clear = function(){ items = []; }; this.size = function(){ return items.length; }; this.print = function(){ console.log(items.toString()); }; } let q = new Queue(); q.enqueue(1); q.enqueue(2); q.enqueue(3); q.print();