Polish queue list solution

This commit is contained in:
Donne Martin 2016-02-21 16:21:05 -05:00
parent 76da9ec98d
commit 7222f71f59
2 changed files with 11 additions and 17 deletions

View File

@ -24,14 +24,11 @@ class Queue(object):
# Empty list
if self.first is None and self.last is None:
return None
data = self.first.data
# Remove only element from a one element list
elif self.first == self.last:
data = self.first.data
if self.first == self.last:
self.first = None
self.last = None
return data
else:
data = self.first.data
self.first = self.first.next
return data
return data

View File

@ -142,17 +142,14 @@
" # Empty list\n",
" if self.first is None and self.last is None:\n",
" return None\n",
"\n",
" data = self.first.data\n",
" # Remove only element from a one element list\n",
" elif self.first == self.last:\n",
" data = self.first.data\n",
" if self.first == self.last:\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"
" return data"
]
},
{
@ -289,21 +286,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
"pygments_lexer": "ipython3",
"version": "3.4.3"
}
},
"nbformat": 4,