mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-07 06:44:57 +08:00
Remove -> None
for Python functions
This commit is contained in:
@ -8,7 +8,7 @@ Author: Krahets (krahets@163.com)
|
||||
class ArrayDeque:
|
||||
"""基于环形数组实现的双向队列"""
|
||||
|
||||
def __init__(self, capacity: int) -> None:
|
||||
def __init__(self, capacity: int):
|
||||
"""构造方法"""
|
||||
self.__nums: list[int] = [0] * capacity
|
||||
self.__front: int = 0
|
||||
@ -33,7 +33,7 @@ class ArrayDeque:
|
||||
# 当 i 越过数组头部后,回到尾部
|
||||
return (i + self.capacity()) % self.capacity()
|
||||
|
||||
def push_first(self, num: int) -> None:
|
||||
def push_first(self, num: int):
|
||||
"""队首入队"""
|
||||
if self.__size == self.capacity():
|
||||
print("双向队列已满")
|
||||
@ -45,7 +45,7 @@ class ArrayDeque:
|
||||
self.__nums[self.__front] = num
|
||||
self.__size += 1
|
||||
|
||||
def push_last(self, num: int) -> None:
|
||||
def push_last(self, num: int):
|
||||
"""队尾入队"""
|
||||
if self.__size == self.capacity():
|
||||
print("双向队列已满")
|
||||
|
@ -8,7 +8,7 @@ Author: Peng Chen (pengchzn@gmail.com)
|
||||
class ArrayQueue:
|
||||
"""基于环形数组实现的队列"""
|
||||
|
||||
def __init__(self, size: int) -> None:
|
||||
def __init__(self, size: int):
|
||||
"""构造方法"""
|
||||
self.__nums: list[int] = [0] * size # 用于存储队列元素的数组
|
||||
self.__front: int = 0 # 队首指针,指向队首元素
|
||||
@ -26,7 +26,7 @@ class ArrayQueue:
|
||||
"""判断队列是否为空"""
|
||||
return self.__size == 0
|
||||
|
||||
def push(self, num: int) -> None:
|
||||
def push(self, num: int):
|
||||
"""入队"""
|
||||
if self.__size == self.capacity():
|
||||
raise IndexError("队列已满")
|
||||
|
@ -8,7 +8,7 @@ Author: Peng Chen (pengchzn@gmail.com)
|
||||
class ArrayStack:
|
||||
"""基于数组实现的栈"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
"""构造方法"""
|
||||
self.__stack: list[int] = []
|
||||
|
||||
@ -20,7 +20,7 @@ class ArrayStack:
|
||||
"""判断栈是否为空"""
|
||||
return self.__stack == []
|
||||
|
||||
def push(self, item: int) -> None:
|
||||
def push(self, item: int):
|
||||
"""入栈"""
|
||||
self.__stack.append(item)
|
||||
|
||||
|
@ -8,7 +8,7 @@ Author: Krahets (krahets@163.com)
|
||||
class ListNode:
|
||||
"""双向链表节点"""
|
||||
|
||||
def __init__(self, val: int) -> None:
|
||||
def __init__(self, val: int):
|
||||
"""构造方法"""
|
||||
self.val: int = val
|
||||
self.next: ListNode | None = None # 后继节点引用(指针)
|
||||
@ -18,7 +18,7 @@ class ListNode:
|
||||
class LinkedListDeque:
|
||||
"""基于双向链表实现的双向队列"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
"""构造方法"""
|
||||
self.front: ListNode | None = None # 头节点 front
|
||||
self.rear: ListNode | None = None # 尾节点 rear
|
||||
@ -32,7 +32,7 @@ class LinkedListDeque:
|
||||
"""判断双向队列是否为空"""
|
||||
return self.size() == 0
|
||||
|
||||
def push(self, num: int, is_front: bool) -> None:
|
||||
def push(self, num: int, is_front: bool):
|
||||
"""入队操作"""
|
||||
node = ListNode(num)
|
||||
# 若链表为空,则令 front, rear 都指向 node
|
||||
@ -52,11 +52,11 @@ class LinkedListDeque:
|
||||
self.rear = node # 更新尾节点
|
||||
self.__size += 1 # 更新队列长度
|
||||
|
||||
def push_first(self, num: int) -> None:
|
||||
def push_first(self, num: int):
|
||||
"""队首入队"""
|
||||
self.push(num, True)
|
||||
|
||||
def push_last(self, num: int) -> None:
|
||||
def push_last(self, num: int):
|
||||
"""队尾入队"""
|
||||
self.push(num, False)
|
||||
|
||||
|
@ -27,7 +27,7 @@ class LinkedListQueue:
|
||||
"""判断队列是否为空"""
|
||||
return not self.__front
|
||||
|
||||
def push(self, num: int) -> None:
|
||||
def push(self, num: int):
|
||||
"""入队"""
|
||||
# 尾节点后添加 num
|
||||
node = ListNode(num)
|
||||
|
@ -26,7 +26,7 @@ class LinkedListStack:
|
||||
"""判断栈是否为空"""
|
||||
return not self.__peek
|
||||
|
||||
def push(self, val: int) -> None:
|
||||
def push(self, val: int):
|
||||
"""入栈"""
|
||||
node = ListNode(val)
|
||||
node.next = self.__peek
|
||||
|
Reference in New Issue
Block a user