Last active
May 5, 2019 20:12
-
-
Save fchikwekwe/d6022f48d23cd06ea063031f1d5efd11 to your computer and use it in GitHub Desktop.
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
def length(self): | |
"""Return the length of this linked list by traversing its nodes.""" | |
node_count = 0 # initial count is zero | |
current = self.head # start at the head | |
# Loop through all nodes | |
while current is not None: | |
current = current.next | |
# add one to the counter each time | |
node_count += 1 | |
# return the total length | |
return node_count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment