Created
January 1, 2020 02:42
-
-
Save Hoxtygen/6aa52c7afb0ccf6bf00d03c5da14426a to your computer and use it in GitHub Desktop.
This file contains hidden or 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() { | |
let items = []; | |
this.enqueue = function (element) { | |
items.push(element); | |
}; | |
this.dequeue = function () { | |
items.shift(); | |
}; | |
this.front = function () { | |
return items[0]; | |
}; | |
this.isEmpty = function () { | |
return items.length === 0; | |
}; | |
this.size = function () { | |
return items.length; | |
} | |
this.print = function () { | |
console.log(items.toString()); | |
}; | |
} | |
let queue = new Queue(); | |
queue.enqueue(12); | |
queue.enqueue(20); | |
queue.enqueue(1); | |
queue.print(); | |
queue.dequeue() | |
console.log(queue.size()); | |
console.log(queue.isEmpty()); | |
queue.enqueue("Nordstrom"); | |
queue.enqueue("Alligator"); | |
queue.enqueue("Nostradamus"); | |
queue.print(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment