Cleared queue challenge code section. Changed references from NULL to None to be more Pythonic.

This commit is contained in:
Donne Martin 2015-07-06 05:47:40 -04:00
parent 8aa4f25354
commit bb1bad1cc7
2 changed files with 12 additions and 29 deletions

View File

@ -39,7 +39,7 @@
"\n", "\n",
"* If there is one item in the list, do you expect the first and last pointers to both point to it?\n", "* If there is one item in the list, do you expect the first and last pointers to both point to it?\n",
" * Yes\n", " * Yes\n",
"* If there are no items on the list, do you expect the first and last pointers to be NULL?\n", "* If there are no items on the list, do you expect the first and last pointers to be None?\n",
" * Yes\n", " * Yes\n",
"* If you dequeue on an empty queue, does that return None?\n", "* If you dequeue on an empty queue, does that return None?\n",
" * Yes" " * Yes"
@ -90,39 +90,22 @@
"class Node(object):\n", "class Node(object):\n",
" \n", " \n",
" def __init__(self, data):\n", " def __init__(self, data):\n",
" self.data = data\n", " # TODO: Implement me\n",
" self.next = None\n", " pass\n",
"\n", "\n",
"class Queue(object):\n", "class Queue(object):\n",
" \n", " \n",
" def __init__(self):\n", " def __init__(self):\n",
" self.first = None\n", " # TODO: Implement me\n",
" self.last = None\n", " pass\n",
"\n", "\n",
" def enqueue(self, data):\n", " def enqueue(self, data):\n",
" node = Node(data)\n", " # TODO: Implement me\n",
" if self.first is None and self.last is None:\n", " pass\n",
" self.first = node\n",
" self.last = node\n",
" else:\n",
" self.last.next = node\n",
" self.last = node\n",
"\n", "\n",
" def dequeue(self):\n", " def dequeue(self):\n",
" # Empty list\n", " # TODO: Implement me\n",
" if self.first is None and self.last is None:\n", " pass"
" return None\n",
" \n",
" # Remove only element from a one element list\n",
" elif self.first == self.last:\n",
" data = self.first.data\n",
" self.first = None\n",
" self.last = None\n",
" return data\n",
" else:\n",
" data = self.first.data\n",
" self.first = self.first.next\n",
" return data"
] ]
}, },
{ {

View File

@ -38,7 +38,7 @@
"\n", "\n",
"* If there is one item in the list, do you expect the first and last pointers to both point to it?\n", "* If there is one item in the list, do you expect the first and last pointers to both point to it?\n",
" * Yes\n", " * Yes\n",
"* If there are no items on the list, do you expect the first and last pointers to be NULL?\n", "* If there are no items on the list, do you expect the first and last pointers to be None?\n",
" * Yes\n", " * Yes\n",
"* If you dequeue on an empty queue, does that return None?\n", "* If you dequeue on an empty queue, does that return None?\n",
" * Yes" " * Yes"
@ -79,10 +79,10 @@
"\n", "\n",
"### Dequeue\n", "### Dequeue\n",
"\n", "\n",
"* If the list is empty, return NULL\n", "* If the list is empty, return None\n",
"* If the list has one node\n", "* If the list has one node\n",
" * Save the first node's value\n", " * Save the first node's value\n",
" * Set first and last to NULL\n", " * Set first and last to None\n",
" * Return the saved value\n", " * Return the saved value\n",
"* Else\n", "* Else\n",
" * Save the first node's value\n", " * Save the first node's value\n",