Skip to content

Instantly share code, notes, and snippets.

@mjarpitanand
Created November 21, 2017 10:17
Show Gist options
  • Save mjarpitanand/1ab2818c8fd91532a1abbbba3f374692 to your computer and use it in GitHub Desktop.
Save mjarpitanand/1ab2818c8fd91532a1abbbba3f374692 to your computer and use it in GitHub Desktop.
function Queue(){
var items = [];
var p = "";
this.enqueue = function(element){
items.push(element);
}
this.dequeue = function(){
items.shift();
}
this.front = function(){
if(items.length === 0){
return 'Null Array';
}else{
return items[0];
}
}
this.isEmpty = function(){
if(items.length === 0){
return false;
}else{
return true;
}
}
this.size = function(){
return items.length;
}
this.print = function(){
for (var i = 0;i < items.length;i++){
p += items[i];
}
return p;
}
}
var q = new Queue();
q.enqueue(1);
q.enqueue(2);
q.enqueue(3);
console.log(q.print());
q.dequeue();
console.log(q.print());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment