mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-27 15:41:16 +08:00
Add annotations to Queue.
This commit is contained in:
parent
260f24b2cb
commit
5eea37837f
@ -5,10 +5,16 @@ export default class Queue {
|
|||||||
this.linkedList = new LinkedList();
|
this.linkedList = new LinkedList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
isEmpty() {
|
isEmpty() {
|
||||||
return !this.linkedList.tail;
|
return !this.linkedList.tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {*}
|
||||||
|
*/
|
||||||
peek() {
|
peek() {
|
||||||
if (!this.linkedList.head) {
|
if (!this.linkedList.head) {
|
||||||
return null;
|
return null;
|
||||||
@ -17,15 +23,25 @@ export default class Queue {
|
|||||||
return this.linkedList.head.value;
|
return this.linkedList.head.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {*} value
|
||||||
|
*/
|
||||||
enqueue(value) {
|
enqueue(value) {
|
||||||
this.linkedList.append(value);
|
this.linkedList.append(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {*}
|
||||||
|
*/
|
||||||
dequeue() {
|
dequeue() {
|
||||||
const removedHead = this.linkedList.deleteHead();
|
const removedHead = this.linkedList.deleteHead();
|
||||||
return removedHead ? removedHead.value : null;
|
return removedHead ? removedHead.value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param [callback]
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
toString(callback) {
|
toString(callback) {
|
||||||
return this.linkedList.toString(callback);
|
return this.linkedList.toString(callback);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user