Update LL delete mid challenge (#112)

Update constraints and assumptions, solution, and test case.
This commit is contained in:
Donne Martin
2016-10-31 07:19:56 -04:00
committed by GitHub
parent 2d651a6eca
commit aa4c8ae5b4
3 changed files with 17 additions and 12 deletions

View File

@@ -36,7 +36,7 @@
"\n",
"* Can we assume this is a non-circular, singly linked list?\n",
" * Yes\n",
"* What if the final node is being deleted, for example a single node list? Do we make it a dummy with value None?\n",
"* What if the final node is being deleted, do we make it a dummy with value None?\n",
" * Yes\n",
"* Can we assume we already have a linked list class that can be used for this problem?\n",
" * Yes"
@@ -141,12 +141,21 @@
"\n",
" print('Test: Multiple nodes')\n",
" linked_list = MyLinkedList(None)\n",
" node0 = linked_list.insert_to_front(1)\n",
" node0 = linked_list.insert_to_front(2)\n",
" node1 = linked_list.insert_to_front(3)\n",
" node2 = linked_list.insert_to_front(4)\n",
" node3 = linked_list.insert_to_front(1)\n",
" linked_list.delete_node(node2)\n",
" assert_equal(linked_list.get_all_data(), [1, 3, 1])\n",
" linked_list.delete_node(node1)\n",
" assert_equal(linked_list.get_all_data(), [1, 4, 2])\n",
"\n",
" print('Test: Multiple nodes, delete last element')\n",
" linked_list = MyLinkedList(None)\n",
" node0 = linked_list.insert_to_front(2)\n",
" node1 = linked_list.insert_to_front(3)\n",
" node2 = linked_list.insert_to_front(4)\n",
" node3 = linked_list.insert_to_front(1)\n",
" linked_list.delete_node(node0)\n",
" assert_equal(linked_list.get_all_data(), [1, 4, 3, None])\n",
"\n",
" print('Success: test_delete_node')\n",
"\n",