Created
November 21, 2017 10:17
-
-
Save mjarpitanand/1ab2818c8fd91532a1abbbba3f374692 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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