Created
June 19, 2022 02:28
-
-
Save wanderindev/8e59b843dafeb289520a6650d9559e38 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
from typing import Any, Union | |
class Node: | |
"""A linked list node implementation""" | |
def __init__(self, node_data: Any) -> None: | |
"""Initialize the node with the given data and pointing to None""" | |
self._data = node_data | |
self._next_node = None | |
def __str__(self) -> str: | |
"""Return a string representation of the node""" | |
return str(self.data) | |
@property | |
def data(self) -> Any: | |
"""Returns the node's data""" | |
return self._data | |
@data.setter | |
def data(self, node_data: Any) -> None: | |
"""Replaces the node's data with the given data""" | |
self._data = node_data | |
@property | |
def next_node(self) -> Union["Node", None]: | |
"""Returns the node's next""" | |
return self._next_node | |
@next_node.setter | |
def next_node(self, next_node: Union["Node", None]) -> None: | |
"""Replaces the node's data with the given data""" | |
self._next_node = next_node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment