Gihub Blog Address
A queue is a special linear table, except that it allows for deletion only at the front end of the table (front), but in the Back-end (rear) of the table, and, like the stack, the queue is a linear table of operations that is Constrained. The end of the insert operation is called the tail of the queue, and the end of the delete operation is called the team Header.
Queue class
function Queue () {this.data = [];}
Add data
Data is added to the end
Enqueue:function (element) {this.data.push (element);}
Delete data
Remove from head
Dequeue:function () {this.data.shift ();}
Get Data
Returns the first
Front:function () {return this.data[0];}
is empty
Isempty:function () {return this.data.length = = 0;}
Clear Data
Clear:function () {this.data= [];}
Data length
Size:function () {return this.data.length;}
Full code
function Queue () {this.data = [];} Queue.prototype = {enqueue:function (element) {this.data.push (element);},dequeue:function () {this.data.shift ();}, Front:function () {return this.data[0];},isempty:function () {return this.data.length = = 0;},clear:function () { This.data = [];},size:function () {return this.data.length;},print:function () {console.log (this.data.toString ())}}
JavaScript data structures-queues