Skip to content

Instantly share code, notes, and snippets.

@pursh2002
Last active December 14, 2023 19:34
Show Gist options
  • Select an option

  • Save pursh2002/e5e49ebc12b62acfba1f0fbb3623661f to your computer and use it in GitHub Desktop.

Select an option

Save pursh2002/e5e49ebc12b62acfba1f0fbb3623661f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Linked list
class Node:
def __init__(self, data):
self.data = data
self.next = None
class My_linkedlist:
def __init__(self):
self.head = None
def append(self, data):
new_node = Node(data)
if self.head is None:
self.head = new_node
return
last_node = self.head
while last_node.next:
last_node = last_node.next
last_node.next = new_node
def print_list(self):
current_node = self.head
while current_node:
print(current_node.data)
current_node = current_node.next
linked_list = My_linkedlist()
linked_list.append("List weekdays from the start:")
linked_list.append("Monday")
linked_list.append("Tuesday")
linked_list.append("Wednesday")
linked_list.append("Thursday")
linked_list.append("Friday")
linked_list.print_list()
"""
Output:
Weekdays:
Monday
Tuesday
Wednesday
Thursday
Friday
"""
print()
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment