更新队列的链表实现中 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:
beintentional 2023-01-27 16:30:37 +00:00 committed by GitHub
parent d76e6582fa
commit 3858048d0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View file

@ -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
# 如果队列不为空,则将该结点添加到尾结点后 # 如果队列不为空,则将该结点添加到尾结点后

View file

@ -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
# 如果队列不为空,则将该结点添加到尾结点后 # 如果队列不为空,则将该结点添加到尾结点后