mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-10 11:09:43 +08:00
feat
size() func. added for linkedlist, doublylinkedlist stack and queue.
This commit is contained in:
parent
8c5e5f4f0d
commit
1782838f50
@ -213,6 +213,10 @@ export default class DoublyLinkedList {
|
|||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size() {
|
||||||
|
return this.toArray().length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {*[]} values - Array of values that need to be converted to linked list.
|
* @param {*[]} values - Array of values that need to be converted to linked list.
|
||||||
* @return {DoublyLinkedList}
|
* @return {DoublyLinkedList}
|
||||||
|
@ -234,6 +234,13 @@ export default class LinkedList {
|
|||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
size() {
|
||||||
|
return this.toArray().length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {function} [callback]
|
* @param {function} [callback]
|
||||||
* @return {string}
|
* @return {string}
|
||||||
|
@ -47,6 +47,14 @@ export default class Queue {
|
|||||||
return removedHead ? removedHead.value : null;
|
return removedHead ? removedHead.value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
size() {
|
||||||
|
return this.linkedList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param [callback]
|
* @param [callback]
|
||||||
* @return {string}
|
* @return {string}
|
||||||
|
@ -48,6 +48,13 @@ export default class Stack {
|
|||||||
return removedHead ? removedHead.value : null;
|
return removedHead ? removedHead.value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
size() {
|
||||||
|
return this.linkedList.size();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {*[]}
|
* @return {*[]}
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user