mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 00:36:28 +08:00
更新队列的链表实现中 self.__front 判空的方式 (#297)
* 更新队列的链表实现中 self.__front 判空的方式 self.__front 初始化为 None, 元素入队判断队列是否为空,延用头节点的初始化值 None 而不是 0 * Update linkedlist_queue.py --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
parent
d76e6582fa
commit
3858048d0f
2 changed files with 2 additions and 2 deletions
|
@ -30,7 +30,7 @@ class LinkedListQueue:
|
||||||
# 尾结点后添加 num
|
# 尾结点后添加 num
|
||||||
node = ListNode(num)
|
node = ListNode(num)
|
||||||
# 如果队列为空,则令头、尾结点都指向该结点
|
# 如果队列为空,则令头、尾结点都指向该结点
|
||||||
if self.__front == 0:
|
if self.__front is None:
|
||||||
self.__front = node
|
self.__front = node
|
||||||
self.__rear = node
|
self.__rear = node
|
||||||
# 如果队列不为空,则将该结点添加到尾结点后
|
# 如果队列不为空,则将该结点添加到尾结点后
|
||||||
|
|
|
@ -412,7 +412,7 @@ comments: true
|
||||||
# 尾结点后添加 num
|
# 尾结点后添加 num
|
||||||
node = ListNode(num)
|
node = ListNode(num)
|
||||||
# 如果队列为空,则令头、尾结点都指向该结点
|
# 如果队列为空,则令头、尾结点都指向该结点
|
||||||
if self.__front == 0:
|
if self.__front is None:
|
||||||
self.__front = node
|
self.__front = node
|
||||||
self.__rear = node
|
self.__rear = node
|
||||||
# 如果队列不为空,则将该结点添加到尾结点后
|
# 如果队列不为空,则将该结点添加到尾结点后
|
||||||
|
|
Loading…
Reference in a new issue