Created
November 13, 2014 08:54
-
-
Save AloofBuddha/d95ad453031b860c484b to your computer and use it in GitHub Desktop.
Linked List search in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# we want to match data, not a Node, as search | |
# shouldn't require any Node creation either | |
def search(self, data): | |
node = self.head | |
while node: | |
if node.data == data: | |
return node | |
else: | |
node = node.nextNode | |
else: | |
raise ValueError("No node with matching data found in Linked List") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment