From d7bc07cc9f2fcd0a05f1cbee06debcfcb560dcbc Mon Sep 17 00:00:00 2001 From: Manish Date: Tue, 22 Aug 2023 10:58:23 +1000 Subject: [PATCH] Data Structures: Create a Queue Class --- Data Structures/queueClass.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Data Structures/queueClass.js diff --git a/Data Structures/queueClass.js b/Data Structures/queueClass.js new file mode 100644 index 0000000..f408ca2 --- /dev/null +++ b/Data Structures/queueClass.js @@ -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 +}