Data Structures: Create a Queue Class
This commit is contained in:
parent
52c60aba48
commit
d7bc07cc9f
25
Data Structures/queueClass.js
Normal file
25
Data Structures/queueClass.js
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user