From 3858048d0fba0a402e94964d32ed45745b29ac1b Mon Sep 17 00:00:00 2001 From: beintentional <117684134+beintentional@users.noreply.github.com> Date: Fri, 27 Jan 2023 16:30:37 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=98=9F=E5=88=97=E7=9A=84?= =?UTF-8?q?=E9=93=BE=E8=A1=A8=E5=AE=9E=E7=8E=B0=E4=B8=AD=20self.=5F=5Ffron?= =?UTF-8?q?t=20=E5=88=A4=E7=A9=BA=E7=9A=84=E6=96=B9=E5=BC=8F=20(#297)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 更新队列的链表实现中 self.__front 判空的方式 self.__front 初始化为 None, 元素入队判断队列是否为空,延用头节点的初始化值 None 而不是 0 * Update linkedlist_queue.py --------- Co-authored-by: Yudong Jin --- codes/python/chapter_stack_and_queue/linkedlist_queue.py | 2 +- docs/chapter_stack_and_queue/queue.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codes/python/chapter_stack_and_queue/linkedlist_queue.py b/codes/python/chapter_stack_and_queue/linkedlist_queue.py index 2ab7196d3..982033a54 100644 --- a/codes/python/chapter_stack_and_queue/linkedlist_queue.py +++ b/codes/python/chapter_stack_and_queue/linkedlist_queue.py @@ -30,7 +30,7 @@ class LinkedListQueue: # 尾结点后添加 num node = ListNode(num) # 如果队列为空,则令头、尾结点都指向该结点 - if self.__front == 0: + if self.__front is None: self.__front = node self.__rear = node # 如果队列不为空,则将该结点添加到尾结点后 diff --git a/docs/chapter_stack_and_queue/queue.md b/docs/chapter_stack_and_queue/queue.md index c7bf098c5..530d16a48 100644 --- a/docs/chapter_stack_and_queue/queue.md +++ b/docs/chapter_stack_and_queue/queue.md @@ -412,7 +412,7 @@ comments: true # 尾结点后添加 num node = ListNode(num) # 如果队列为空,则令头、尾结点都指向该结点 - if self.__front == 0: + if self.__front is None: self.__front = node self.__rear = node # 如果队列不为空,则将该结点添加到尾结点后