Skip to content

Instantly share code, notes, and snippets.

@MinaGabriel
Created October 28, 2020 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MinaGabriel/9c6804fb6858752bac1df74045197f55 to your computer and use it in GitHub Desktop.
Save MinaGabriel/9c6804fb6858752bac1df74045197f55 to your computer and use it in GitHub Desktop.
class Node:
def __init__(self, element = None, next_node = None):
self._element = element
self._next = next_node
def get_element(self):
return self._element
def get_next(self):
return self._next
def set_element(self, new_element):
if self._element is None:
self._element = new_element
def set_next(self, new_next):
old_next = self._next
self._next = new_next
return old_next
head = Node(5)
head = Node(10, head)
head = Node(25, head)
head = Node(15, head)
head = Node(20, head)
print('head', end='-->')
while head != None:
print( '| ' + str(head.get_element()) + ' |' , end='-->')
head = head.get_next()
print('None')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment