Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Queue() {
- this.collection = [];
- // print the queue collection
- this.print = function () {
- return this.collection;
- };
- this.enqueue = function (element) {
- this.collection.push(element);
- };
- this.dequeue = function () {
- this.collection.shift();
- };
- this.front = function () {
- return this.collection[0];
- };
- this.size = function () {
- return this.collection.length;
- };
- this.isEmpty = function () {
- return this.collection.length === 0;
- };
- };
- const myQueue = new Queue();
- myQueue.enqueue(10);
- myQueue.enqueue(20);
- myQueue.enqueue(30);
- console.log(myQueue.print());
- console.log(myQueue.front());
- myQueue.dequeue();
- console.log(myQueue.print());
- console.log(myQueue.size());
- console.log(myQueue.isEmpty());
- myQueue.dequeue();
- myQueue.dequeue();
- console.log(myQueue.isEmpty());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement