mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Polish queue list solution
This commit is contained in:
parent
76da9ec98d
commit
7222f71f59
|
@ -24,14 +24,11 @@ class Queue(object):
|
||||||
# Empty list
|
# Empty list
|
||||||
if self.first is None and self.last is None:
|
if self.first is None and self.last is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Remove only element from a one element list
|
|
||||||
elif self.first == self.last:
|
|
||||||
data = self.first.data
|
data = self.first.data
|
||||||
|
# Remove only element from a one element list
|
||||||
|
if self.first == self.last:
|
||||||
self.first = None
|
self.first = None
|
||||||
self.last = None
|
self.last = None
|
||||||
return data
|
|
||||||
else:
|
else:
|
||||||
data = self.first.data
|
|
||||||
self.first = self.first.next
|
self.first = self.first.next
|
||||||
return data
|
return data
|
|
@ -142,15 +142,12 @@
|
||||||
" # Empty list\n",
|
" # Empty list\n",
|
||||||
" if self.first is None and self.last is None:\n",
|
" if self.first is None and self.last is None:\n",
|
||||||
" return 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",
|
" data = self.first.data\n",
|
||||||
|
" # Remove only element from a one element list\n",
|
||||||
|
" if self.first == self.last:\n",
|
||||||
" self.first = None\n",
|
" self.first = None\n",
|
||||||
" self.last = None\n",
|
" self.last = None\n",
|
||||||
" return data\n",
|
|
||||||
" else:\n",
|
" else:\n",
|
||||||
" data = self.first.data\n",
|
|
||||||
" self.first = self.first.next\n",
|
" self.first = self.first.next\n",
|
||||||
" return data"
|
" return data"
|
||||||
]
|
]
|
||||||
|
@ -289,21 +286,21 @@
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python 2",
|
"display_name": "Python 3",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "python2"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
"language_info": {
|
"language_info": {
|
||||||
"codemirror_mode": {
|
"codemirror_mode": {
|
||||||
"name": "ipython",
|
"name": "ipython",
|
||||||
"version": 2
|
"version": 3
|
||||||
},
|
},
|
||||||
"file_extension": ".py",
|
"file_extension": ".py",
|
||||||
"mimetype": "text/x-python",
|
"mimetype": "text/x-python",
|
||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython2",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "2.7.10"
|
"version": "3.4.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user