size() func. added for linkedlist, doublylinkedlist stack and queue.
This commit is contained in:
Kerim Şentürk 2023-06-26 02:26:50 +03:00
parent 8c5e5f4f0d
commit 1782838f50
4 changed files with 26 additions and 0 deletions

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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 {*[]}
*/ */