mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
fixes the alternative delete method (alt_delete) so that it properly handles the deletion of the head node
This commit is contained in:
parent
9ab9d70229
commit
f6c38841bb
|
@ -170,7 +170,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -258,10 +258,10 @@
|
|||
" return\n",
|
||||
" if self.head is None:\n",
|
||||
" return\n",
|
||||
" curr_node = self.head\n",
|
||||
" if curr_node.data == data:\n",
|
||||
" curr_node = curr_node.next\n",
|
||||
" if self.head.data == data:\n",
|
||||
" self.head = self.head.next\n",
|
||||
" return\n",
|
||||
" curr_node = self.head\n",
|
||||
" while curr_node.next is not None:\n",
|
||||
" if curr_node.next.data == data:\n",
|
||||
" curr_node.next = curr_node.next.next\n",
|
||||
|
@ -285,7 +285,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -301,7 +301,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -443,7 +443,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -468,6 +468,7 @@
|
|||
"\n",
|
||||
"Test: delete on an empty list\n",
|
||||
"Test: delete a None\n",
|
||||
"Test: delete general case with match at the head\n",
|
||||
"Test: delete general case with matches\n",
|
||||
"Test: delete general case with no matches\n",
|
||||
"Success: test_delete\n",
|
||||
|
|
Loading…
Reference in New Issue
Block a user