mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-09 08:05:35 +08:00
Add typing annotations to Python codes. (#411)
This commit is contained in:
@ -4,9 +4,7 @@ Created Time: 2022-11-29
|
||||
Author: Peng Chen (pengchzn@gmail.com)
|
||||
"""
|
||||
|
||||
import os.path as osp
|
||||
import sys
|
||||
|
||||
import sys, os.path as osp
|
||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
||||
from modules import *
|
||||
|
||||
@ -14,9 +12,9 @@ from modules import *
|
||||
""" Driver Code """
|
||||
if __name__ == "__main__":
|
||||
""" 初始化队列 """
|
||||
# 在 Python 中,我们一般将双向队列类 deque 看左队列使用
|
||||
# 虽然 queue.Queue() 是纯正的队列类,但不太好用,因此不建议
|
||||
que = collections.deque()
|
||||
# 在 Python 中,我们一般将双向队列类 deque 看作队列使用
|
||||
# 虽然 queue.Queue() 是纯正的队列类,但不太好用
|
||||
que: Deque[int] = collections.deque()
|
||||
|
||||
""" 元素入队 """
|
||||
que.append(1)
|
||||
@ -27,18 +25,18 @@ if __name__ == "__main__":
|
||||
print("队列 que =", que)
|
||||
|
||||
""" 访问队首元素 """
|
||||
front = que[0];
|
||||
print("队首元素 front =", front);
|
||||
front: int = que[0]
|
||||
print("队首元素 front =", front)
|
||||
|
||||
""" 元素出队 """
|
||||
pop = que.popleft()
|
||||
pop: int = que.popleft()
|
||||
print("出队元素 pop =", pop)
|
||||
print("出队后 que =", que)
|
||||
|
||||
""" 获取队列的长度 """
|
||||
size = len(que)
|
||||
size: int = len(que)
|
||||
print("队列长度 size =", size)
|
||||
|
||||
""" 判断队列是否为空 """
|
||||
is_empty = len(que) == 0
|
||||
is_empty: bool = len(que) == 0
|
||||
print("队列是否为空 =", is_empty)
|
||||
|
Reference in New Issue
Block a user