Created
June 19, 2022 02:30
-
-
Save wanderindev/b6dbc2824f1ae5bbe42bb003983927d8 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
def get_last_node(self) -> "Node": | |
"""Return the last node in the linked list""" | |
current_node = self.head | |
while current_node.next_node is not None: | |
current_node = current_node.next_node | |
return current_node | |
def get_node(self, node_data: Any) -> Union["Node", None]: | |
"""Return the first node whose data is node_data or None""" | |
current_node = self.head | |
while current_node.data != node_data: | |
if not current_node: | |
return None | |
current_node = current_node.next_node | |
return current_node | |
def get_prev_node(self, node_data: Any) -> Union["Node", None]: | |
"""Return the node before first node whose data is node_data or None""" | |
current_node = self.head | |
prev_node = None | |
while current_node.data != node_data: | |
if not current_node: | |
return None | |
prev_node = current_node | |
current_node = current_node.next_node | |
return prev_node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment