diff --git a/data_structures/3_LinkedList/Solution/singly_linked_list_exercise.py b/data_structures/3_LinkedList/Solution/singly_linked_list_exercise.py index cce871c..d5aa057 100644 --- a/data_structures/3_LinkedList/Solution/singly_linked_list_exercise.py +++ b/data_structures/3_LinkedList/Solution/singly_linked_list_exercise.py @@ -110,13 +110,20 @@ def remove_by_value(self, data): if self.head.data == data: self.head = self.head.next return - + + initial_length = self.get_length() + count = 0 itr = self.head while itr.next: if itr.next.data == data: itr.next = itr.next.next break itr = itr.next + count += 1 + + if count == initial_length: + raise Exception("The specified element is not present in the linked list") + if __name__ == '__main__': ll = LinkedList() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy