mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 07:01:18 +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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
isEmpty() {
|
||||
return !this.linkedList.tail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
peek() {
|
||||
if (!this.linkedList.head) {
|
||||
return null;
|
||||
@ -17,15 +23,25 @@ export default class Queue {
|
||||
return this.linkedList.head.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} value
|
||||
*/
|
||||
enqueue(value) {
|
||||
this.linkedList.append(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
dequeue() {
|
||||
const removedHead = this.linkedList.deleteHead();
|
||||
return removedHead ? removedHead.value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param [callback]
|
||||
* @return {string}
|
||||
*/
|
||||
toString(callback) {
|
||||
return this.linkedList.toString(callback);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user