Skip to content

Commit

Permalink
feat(doubly-linked-list): delete nodes by key
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianLusina committed Jun 5, 2024
1 parent 373a150 commit 6b4dda7
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,22 @@ class DoublyLinkedList<T> : LinkedList<DoublyLinkedListNode<T>, T>() {
}

override fun deleteNodesByKey(key: String): Collection<DoublyLinkedListNode<T>> {
TODO("Not yet implemented")
val deletedNodes = arrayListOf<DoublyLinkedListNode<T>>()

if (head == null) {
return emptyList()
}

var current = head
while (current != null) {
if (current.key == key) {
deleteNodeByKey(key)
deletedNodes.add(current)
}
current = current.next
}

return deletedNodes
}

override fun deleteMiddle(): DoublyLinkedListNode<T>? {
Expand Down

0 comments on commit 6b4dda7

Please sign in to comment.