Created
July 24, 2023 22:04
-
-
Save tjarratt/ecf590d44c8cd0454c441c33533eef3f to your computer and use it in GitHub Desktop.
Basic Python Linked List
This file contains hidden or 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
class Node: | |
def __init__(self, val): | |
self.__value = val | |
self.__next = None | |
def add(self, next_): | |
self.__next = next_ | |
def value(self): | |
return self.__value | |
def next(self): | |
return self.__next | |
def size(self): | |
size = 1 | |
next_ = self.next() | |
while next_ is not None: | |
size += 1 | |
next_ = next_.next() | |
return size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment