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

View File

@ -38,7 +38,7 @@
"\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",
"* 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",
"* If you dequeue on an empty queue, does that return None?\n",
" * Yes"
@ -79,10 +79,10 @@
"\n",
"### Dequeue\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",
" * 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",
"* Else\n",
" * Save the first node's value\n",