Skip to content

Instantly share code, notes, and snippets.

@tjarratt
Created July 24, 2023 22:04
Show Gist options
  • Save tjarratt/ecf590d44c8cd0454c441c33533eef3f to your computer and use it in GitHub Desktop.
Save tjarratt/ecf590d44c8cd0454c441c33533eef3f to your computer and use it in GitHub Desktop.
Basic Python Linked List
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