Queue Implementation

Run Settings
LanguageJavaScript
Language Version
Run Command
class Node { constructor(value){ this.value = value this.next = null } } class Queue{ constructor(){ this.first = null; this.last = null; this.length = 0; } peek(){ return this.first; } enqueue(value){ const node = new Node(value); if(!this.first){ this.first = node; } else { this.last.next = node; //this.first.next = node; } this.last = node; this.length++; return this; } dequeue(){ if(!this.first){ return null; } if(this.first == this.last){ this.last = null; } this.first = this.first.next; this.length--; return this; } } const myQueue = new Queue(); myQueue.enqueue("Ami"); myQueue.enqueue("Tumi"); myQueue.enqueue("Onno keu"); myQueue.dequeue(); //myQueue.peek();
Editor Settings
Theme
Key bindings
Full width
Lines