LinkedList<T>.delete
Overloads
Variant | Definition |
---|---|
delete(node: LinkedListNode<T>): LinkedListNode<T> | Removes the first occurrence of a node from the LinkedList<T> . |
delete(value: T): LinkedListNode<T> | Removes the first occurrence of the specified value from the LinkedList<T> . |
delete(node: LinkedListNode<T>): LinkedListNode<T>
Removes the first occurrence of a node from the LinkedList<T>
.
Parameters
nodeLinkedListNode<T>
: The LinkedListNode<T>
to remove from the LinkedList<T>
.
Example
typescript
const list = new LinkedList<number>([1, 2, 3, 4]);
list.length // => 4
list.delete(4)
list.length // => 3
list.last // => LinkListNode(3)
Remarks
This method is an O(1) operation.
delete(value: T): LinkedListNode<T>
Removes the first occurrence of the specified value from the LinkedList<T>
.
Parameters
valueT
: The value to remove from the LinkedList<T>
.
Returns
LinkedListNode<T>
true
if the element containing value is successfully removed; otherwise, false
. This method also returns false
if value was not found in the original LinkedList<T>
.
Example
typescript
const list = new LinkedList<number>([1, 2, 3, 4]);
list.length // => 4
list.delete(4)
list.length // => 3
list.last // => LinkListNode(3)
Remarks
This method is an O(1) operation.