Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript queue

class Queue {
  constructor() {
    this.records = [];
  }
  
  enqueue(record) {
    this.records.unshift(record);
  }
  
  dequeue() {
    return this.records.pop();
  }
  
  peek() {
    return this.records[this.records.length-1];
  }
  
  print() {
   console.log('The queue records are -', this.records); 
  }
}
Source by codeburst.io #
 
PREVIOUS NEXT
Tagged: #javascript #queue
ADD COMMENT
Topic
Name
2+1 =