Data Structures: Create a Queue Class

This commit is contained in:
Manish 2023-08-22 10:58:23 +10:00
parent 52c60aba48
commit d7bc07cc9f

View File

@ -0,0 +1,25 @@
// https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/create-a-queue-class
function Queue() {
var collection = [];
this.print = function () {
console.log(collection);
};
// Only change code below this line
this.enqueue = function (elem) {
collection.push(elem);
};
this.dequeue = function () {
return collection.shift();
};
this.front = function () {
return collection[0];
};
this.size = function () {
return collection.length;
};
this.isEmpty = function () {
return !collection.length;
};
// Only change code above this line
}