Skip to content

Instantly share code, notes, and snippets.

@wanderindev
Created June 19, 2022 02:28
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/8e59b843dafeb289520a6650d9559e38 to your computer and use it in GitHub Desktop.
Save wanderindev/8e59b843dafeb289520a6650d9559e38 to your computer and use it in GitHub Desktop.
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