Skip to content

Instantly share code, notes, and snippets.

@mjcarnaje
Created October 5, 2022 12:42
Show Gist options
  • Save mjcarnaje/96098c2f99b1f96125f08db53233098f to your computer and use it in GitHub Desktop.
Save mjcarnaje/96098c2f99b1f96125f08db53233098f to your computer and use it in GitHub Desktop.
class Link:
def __init__(self):
self.value = None
self.nextLink = None
def setValue(self, value):
self.value = value
def setNext(self, nextLink):
self.nextLink = nextLink
head = Link()
head.setValue(1)
head.setNext(None)
current = head
for i in range(2, 21):
newLink = Link()
newLink.setValue(i)
newLink.setNext(head)
current.setNext(newLink)
current = newLink
current = head
for i in range(0, 21):
print(current.value)
current = current.nextLink
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment