This notebook was prepared by Donne Martin. Source and license info is on GitHub.

Challenge Notebook¶

Constraints¶

• Can we assume this is a non-circular, singly linked list?
• Yes
• What if the final node is being deleted, do we make it a dummy with value None?
• Yes
• Can we assume we already have a linked list class that can be used for this problem?
• Yes

Test Cases¶

• Delete on empty list -> None
• Delete None -> None
• Delete on one node -> [None]
• Delete on multiple nodes

Algorithm¶

Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.

Code¶

In [ ]:
%run ../linked_list/linked_list.py

In [ ]:
class MyLinkedList(LinkedList):

def delete_node(self, node):
# TODO: Implement me
pass


Unit Test¶

The following unit test is expected to fail until you solve the challenge.

In [ ]:
# %load test_delete_mid.py
import unittest

class TestDeleteNode(unittest.TestCase):

def test_delete_node(self):
print('Test: Empty list, null node to delete')

print('Test: One node')

print('Test: Multiple nodes')

print('Test: Multiple nodes, delete last element')

print('Success: test_delete_node')

def main():
test = TestDeleteNode()
test.test_delete_node()

if __name__ == '__main__':
main()


Solution Notebook¶

Review the Solution Notebook for a discussion on algorithms and code solutions.