Skip to content

Instantly share code, notes, and snippets.

@wanderindev
Created June 19, 2022 02:29
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 wanderindev/be833e105b3cc275e933fc28a9ee64b7 to your computer and use it in GitHub Desktop.
Save wanderindev/be833e105b3cc275e933fc28a9ee64b7 to your computer and use it in GitHub Desktop.
class SinglyLinkedList:
"""A singly linked list implementation"""
def __init__(self) -> None:
"""Initialize a singly link list where the head is None"""
self.head = None
def __str__(self) -> str:
"""Return a string representation of the linked list"""
sll_nodes = []
current_node = self.head
while current_node is not None:
sll_nodes.append(str(current_node.data))
current_node = current_node.next_node
sll_nodes.append(str(None))
return " -> ".join(sll_nodes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment