Created
June 19, 2022 02:29
-
-
Save wanderindev/be833e105b3cc275e933fc28a9ee64b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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