Created
June 19, 2022 02:33
-
-
Save wanderindev/b3eb0c1ec70ee7cec5d360aeba784df9 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 add_before(self, node_data: Any, new_data: Any) -> None: | |
"""Add a node before the first node whose data is node_data""" | |
new_node = Node(new_data) | |
insert_at_node = self.get_prev_node(node_data) | |
if insert_at_node: | |
new_node.next_node = insert_at_node.next_node | |
insert_at_node.next_node = new_node | |
else: | |
self.add_front(new_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment