Retranslate the complete English edition from Simplified Chinese (#2010)

* Retranslate the complete English edition from Simplified Chinese

* Polish three English explanations after reader-focused review
This commit is contained in:
Yudong Jin
2026-10-31 03:35:51 +08:00
committed by GitHub
parent ef46e2ed95
commit 14c314c08c
1502 changed files with 29459 additions and 23517 deletions

View File

@@ -6,7 +6,7 @@ Author: krahets (krahets@163.com)
class ArrayDeque:
"""Double-ended queue based on circular array implementation"""
"""Deque implemented with a circular array"""
def __init__(self, capacity: int):
"""Constructor"""
@@ -15,115 +15,115 @@ class ArrayDeque:
self._size: int = 0
def capacity(self) -> int:
"""Get the capacity of the double-ended queue"""
"""Get the deque capacity"""
return len(self._nums)
def size(self) -> int:
"""Get the length of the double-ended queue"""
"""Get the deque size"""
return self._size
def is_empty(self) -> bool:
"""Check if the double-ended queue is empty"""
"""Check whether the deque is empty"""
return self._size == 0
def index(self, i: int) -> int:
"""Calculate circular array index"""
# Use modulo operation to wrap the array head and tail together
# When i passes the tail of the array, return to the head
# When i passes the head of the array, return to the tail
"""Calculate an index in the circular array"""
# Use modulo to connect the end of the array to its beginning
# When i passes the end of the array, wrap around to the beginning
# When i passes the beginning of the array, wrap around to the end
return (i + self.capacity()) % self.capacity()
def push_first(self, num: int):
"""Front of the queue enqueue"""
"""Enqueue at the front"""
if self._size == self.capacity():
print("Double-ended queue is full")
print("Deque is full")
return
# Front pointer moves one position to the left
# Use modulo operation to wrap front around to the tail after passing the head of the array
# Move the front pointer one position to the left
# Use modulo to wrap front to the end when it passes the beginning of the array
self._front = self.index(self._front - 1)
# Add num to the front of the queue
# Add num to the front
self._nums[self._front] = num
self._size += 1
def push_last(self, num: int):
"""Rear of the queue enqueue"""
"""Enqueue at the rear"""
if self._size == self.capacity():
print("Double-ended queue is full")
print("Deque is full")
return
# Calculate rear pointer, points to rear index + 1
# Calculate the rear pointer, which points one position past the last element
rear = self.index(self._front + self._size)
# Add num to the rear of the queue
# Add num to the rear
self._nums[rear] = num
self._size += 1
def pop_first(self) -> int:
"""Front of the queue dequeue"""
"""Dequeue from the front"""
num = self.peek_first()
# Front pointer moves one position backward
# Advance the front pointer by one position
self._front = self.index(self._front + 1)
self._size -= 1
return num
def pop_last(self) -> int:
"""Rear of the queue dequeue"""
"""Dequeue from the rear"""
num = self.peek_last()
self._size -= 1
return num
def peek_first(self) -> int:
"""Access front of the queue element"""
"""Access the front element"""
if self.is_empty():
raise IndexError("Double-ended queue is empty")
raise IndexError("Deque is empty")
return self._nums[self._front]
def peek_last(self) -> int:
"""Access rear of the queue element"""
"""Access the rear element"""
if self.is_empty():
raise IndexError("Double-ended queue is empty")
# Calculate tail element index
raise IndexError("Deque is empty")
# Calculate the index of the last element
last = self.index(self._front + self._size - 1)
return self._nums[last]
def to_array(self) -> list[int]:
"""Return array for printing"""
# Only convert list elements within the valid length range
"""Return an array for printing"""
# Convert only the list elements within the occupied range
res = []
for i in range(self._size):
res.append(self._nums[self.index(self._front + i)])
return res
"""Driver Code"""
"""Driver code"""
if __name__ == "__main__":
# Initialize double-ended queue
# Initialize the deque
deque = ArrayDeque(10)
deque.push_last(3)
deque.push_last(2)
deque.push_last(5)
print("double-ended queue deque =", deque.to_array())
print("Deque deque =", deque.to_array())
# Access elements
# Access an element
peek_first: int = deque.peek_first()
print("Front of the queue element peek_first =", peek_first)
print("Front element peek_first =", peek_first)
peek_last: int = deque.peek_last()
print("Rear of the queue element peek_last =", peek_last)
print("Rear element peek_last =", peek_last)
# Elements enqueue
# Enqueue elements
deque.push_last(4)
print("Element 4 rear enqueue after deque =", deque.to_array())
print("After enqueuing element 4 at the rear, deque =", deque.to_array())
deque.push_first(1)
print("Element 1 front enqueue after deque =", deque.to_array())
print("After enqueuing element 1 at the front, deque =", deque.to_array())
# Elements dequeue
# Dequeue an element
pop_last: int = deque.pop_last()
print("Rear dequeued element =", pop_last, ", rear dequeue after deque =", deque.to_array())
print("Element dequeued from the rear =", pop_last, ", after dequeuing from the rear, deque =", deque.to_array())
pop_first: int = deque.pop_first()
print("Front dequeued element =", pop_first, ", front dequeue after deque =", deque.to_array())
print("Element dequeued from the front =", pop_first, ", after dequeuing from the front, deque =", deque.to_array())
# Get the length of the double-ended queue
# Get the deque size
size: int = deque.size()
print("Length of the double-ended queue size =", size)
print("Deque size =", size)
# Check if the double-ended queue is empty
# Check whether the deque is empty
is_empty: bool = deque.is_empty()
print("Is the double-ended queue empty =", is_empty)
print("Is the deque empty =", is_empty)

View File

@@ -6,53 +6,53 @@ Author: Peng Chen (pengchzn@gmail.com)
class ArrayQueue:
"""Queue based on circular array implementation"""
"""Queue implemented with a circular array"""
def __init__(self, size: int):
"""Constructor"""
self._nums: list[int] = [0] * size # Array for storing queue elements
self._front: int = 0 # Front pointer, points to the front of the queue element
self._size: int = 0 # Queue length
self._nums: list[int] = [0] * size # Array that stores the queue elements
self._front: int = 0 # Front pointer, pointing to the first element
self._size: int = 0 # Queue size
def capacity(self) -> int:
"""Get the capacity of the queue"""
"""Get the queue capacity"""
return len(self._nums)
def size(self) -> int:
"""Get the length of the queue"""
"""Get the queue size"""
return self._size
def is_empty(self) -> bool:
"""Check if the queue is empty"""
"""Check whether the queue is empty"""
return self._size == 0
def push(self, num: int):
"""Enqueue"""
if self._size == self.capacity():
raise IndexError("Queue is full")
# Calculate rear pointer, points to rear index + 1
# Use modulo operation to wrap rear around to the head after passing the tail of the array
# Calculate the rear pointer, which points one position past the last element
# Use modulo to wrap rear to the beginning when it passes the end of the array
rear: int = (self._front + self._size) % self.capacity()
# Add num to the rear of the queue
# Add num to the rear
self._nums[rear] = num
self._size += 1
def pop(self) -> int:
"""Dequeue"""
num: int = self.peek()
# Front pointer moves one position backward, if it passes the tail, return to the head of the array
# Advance the front pointer by one position, wrapping to the beginning if it passes the end
self._front = (self._front + 1) % self.capacity()
self._size -= 1
return num
def peek(self) -> int:
"""Access front of the queue element"""
"""Access the front element"""
if self.is_empty():
raise IndexError("Queue is empty")
return self._nums[self._front]
def to_list(self) -> list[int]:
"""Return list for printing"""
"""Return a list for printing"""
res = [0] * self.size()
j: int = self._front
for i in range(self.size()):
@@ -61,38 +61,38 @@ class ArrayQueue:
return res
"""Driver Code"""
"""Driver code"""
if __name__ == "__main__":
# Initialize queue
# Initialize the queue
queue = ArrayQueue(10)
# Elements enqueue
# Enqueue elements
queue.push(1)
queue.push(3)
queue.push(2)
queue.push(5)
queue.push(4)
print("queue =", queue.to_list())
print("Queue queue =", queue.to_list())
# Access front of the queue element
# Access the front element
peek: int = queue.peek()
print("Front of the queue element peek =", peek)
print("Front element peek =", peek)
# Element dequeue
# Dequeue an element
pop: int = queue.pop()
print("Dequeued element pop =", pop)
print("After dequeue queue =", queue.to_list())
print("After dequeuing, queue =", queue.to_list())
# Get the length of the queue
# Get the queue size
size: int = queue.size()
print("Length of the queue size =", size)
print("Queue size =", size)
# Check if the queue is empty
# Check whether the queue is empty
is_empty: bool = queue.is_empty()
print("Is the queue empty =", is_empty)
# Test circular array
# Test the circular array
for i in range(10):
queue.push(i)
queue.pop()
print("Round", i, "enqueue + dequeue after queue = ", queue.to_list())
print("Round", i, ": after enqueue + dequeue, queue = ", queue.to_list())

View File

@@ -6,18 +6,18 @@ Author: Peng Chen (pengchzn@gmail.com)
class ArrayStack:
"""Stack based on array implementation"""
"""Stack implemented with an array"""
def __init__(self):
"""Constructor"""
self._stack: list[int] = []
def size(self) -> int:
"""Get the length of the stack"""
"""Get the stack size"""
return len(self._stack)
def is_empty(self) -> bool:
"""Check if the stack is empty"""
"""Check whether the stack is empty"""
return self.size() == 0
def push(self, item: int):
@@ -31,42 +31,42 @@ class ArrayStack:
return self._stack.pop()
def peek(self) -> int:
"""Access top of the stack element"""
"""Access the top element"""
if self.is_empty():
raise IndexError("Stack is empty")
return self._stack[-1]
def to_list(self) -> list[int]:
"""Return list for printing"""
"""Return a list for printing"""
return self._stack
"""Driver Code"""
"""Driver code"""
if __name__ == "__main__":
# Initialize stack
# Initialize the stack
stack = ArrayStack()
# Elements push onto stack
# Push elements onto the stack
stack.push(1)
stack.push(3)
stack.push(2)
stack.push(5)
stack.push(4)
print("stack =", stack.to_list())
print("Stack stack =", stack.to_list())
# Access top of the stack element
# Access the top element
peek: int = stack.peek()
print("Top of the stack element peek =", peek)
print("Top element peek =", peek)
# Element pop from stack
# Pop an element from the stack
pop: int = stack.pop()
print("Popped element pop =", pop)
print("After pop stack =", stack.to_list())
print("After popping, stack =", stack.to_list())
# Get the length of the stack
# Get the stack size
size: int = stack.size()
print("Length of the stack size =", size)
print("Stack size =", size)
# Check if it is empty
# Check whether it is empty
is_empty: bool = stack.is_empty()
print("Is the stack empty =", is_empty)

View File

@@ -6,37 +6,37 @@ Author: Peng Chen (pengchzn@gmail.com)
from collections import deque
"""Driver Code"""
"""Driver code"""
if __name__ == "__main__":
# Initialize double-ended queue
# Initialize the deque
deq: deque[int] = deque()
# Elements enqueue
deq.append(2) # Add to the rear of the queue
# Enqueue elements
deq.append(2) # Add to the rear
deq.append(5)
deq.append(4)
deq.appendleft(3) # Add to the front of the queue
deq.appendleft(3) # Add to the front
deq.appendleft(1)
print("double-ended queue deque =", deq)
print("Deque deq =", deq)
# Access elements
front: int = deq[0] # Front of the queue element
print("Front of the queue element front =", front)
rear: int = deq[-1] # Rear of the queue element
print("Rear of the queue element rear =", rear)
# Access an element
front: int = deq[0] # Front element
print("Front element front =", front)
rear: int = deq[-1] # Rear element
print("Rear element rear =", rear)
# Elements dequeue
pop_front: int = deq.popleft() # Front of the queue element dequeues
print("Front dequeued element pop_front =", pop_front)
print("After front dequeue deque =", deq)
pop_rear: int = deq.pop() # Rear of the queue element dequeues
print("Rear dequeued element pop_rear =", pop_rear)
print("After rear dequeue deque =", deq)
# Dequeue an element
pop_front: int = deq.popleft() # Dequeue the front element
print("Element dequeued from the front, pop_front =", pop_front)
print("After dequeuing from the front, deq =", deq)
pop_rear: int = deq.pop() # Dequeue the rear element
print("Element dequeued from the rear, pop_rear =", pop_rear)
print("After dequeuing from the rear, deq =", deq)
# Get the length of the double-ended queue
# Get the deque size
size: int = len(deq)
print("Length of the double-ended queue size =", size)
print("Deque size =", size)
# Check if the double-ended queue is empty
# Check whether the deque is empty
is_empty: bool = len(deq) == 0
print("Is the double-ended queue empty =", is_empty)
print("Is the deque empty =", is_empty)

View File

@@ -11,25 +11,25 @@ class ListNode:
def __init__(self, val: int):
"""Constructor"""
self.val: int = val
self.next: ListNode | None = None # Successor node reference
self.prev: ListNode | None = None # Predecessor node reference
self.next: ListNode | None = None # Reference to the next node
self.prev: ListNode | None = None # Reference to the previous node
class LinkedListDeque:
"""Double-ended queue based on doubly linked list implementation"""
"""Deque implemented with a doubly linked list"""
def __init__(self):
"""Constructor"""
self._front: ListNode | None = None # Head node front
self._rear: ListNode | None = None # Tail node rear
self._size: int = 0 # Length of the double-ended queue
self._size: int = 0 # Deque size
def size(self) -> int:
"""Get the length of the double-ended queue"""
"""Get the deque size"""
return self._size
def is_empty(self) -> bool:
"""Check if the double-ended queue is empty"""
"""Check whether the deque is empty"""
return self._size == 0
def push(self, num: int, is_front: bool):
@@ -38,78 +38,78 @@ class LinkedListDeque:
# If the linked list is empty, make both front and rear point to node
if self.is_empty():
self._front = self._rear = node
# Front of the queue enqueue operation
# Enqueue at the front
elif is_front:
# Add node to the head of the linked list
self._front.prev = node
node.next = self._front
self._front = node # Update head node
# Rear of the queue enqueue operation
self._front = node # Update the head node
# Enqueue at the rear
else:
# Add node to the tail of the linked list
self._rear.next = node
node.prev = self._rear
self._rear = node # Update tail node
self._size += 1 # Update queue length
self._rear = node # Update the tail node
self._size += 1 # Update the deque size
def push_first(self, num: int):
"""Front of the queue enqueue"""
"""Enqueue at the front"""
self.push(num, True)
def push_last(self, num: int):
"""Rear of the queue enqueue"""
"""Enqueue at the rear"""
self.push(num, False)
def pop(self, is_front: bool) -> int:
"""Dequeue operation"""
if self.is_empty():
raise IndexError("Double-ended queue is empty")
# When the deque has one element, front and rear point to the same node
raise IndexError("Deque is empty")
# When the deque size is 1, the head and tail point to the same node
if self._size == 1:
val: int = self._front.val
self._front = None
self._rear = None
# Front of the queue dequeue operation
# Dequeue from the front
elif is_front:
val: int = self._front.val # Temporarily store head node value
# Delete head node
val: int = self._front.val # Save the head node value
# Remove the head node
fnext: ListNode | None = self._front.next
fnext.prev = None
self._front.next = None
self._front = fnext # Update head node
# Rear of the queue dequeue operation
self._front = fnext # Update the head node
# Dequeue from the rear
else:
val: int = self._rear.val # Temporarily store tail node value
# Delete tail node
val: int = self._rear.val # Save the tail node value
# Remove the tail node
rprev: ListNode | None = self._rear.prev
rprev.next = None
self._rear.prev = None
self._rear = rprev # Update tail node
self._size -= 1 # Update queue length
self._rear = rprev # Update the tail node
self._size -= 1 # Update the deque size
return val
def pop_first(self) -> int:
"""Front of the queue dequeue"""
"""Dequeue from the front"""
return self.pop(True)
def pop_last(self) -> int:
"""Rear of the queue dequeue"""
"""Dequeue from the rear"""
return self.pop(False)
def peek_first(self) -> int:
"""Access front of the queue element"""
"""Access the front element"""
if self.is_empty():
raise IndexError("Double-ended queue is empty")
raise IndexError("Deque is empty")
return self._front.val
def peek_last(self) -> int:
"""Access rear of the queue element"""
"""Access the rear element"""
if self.is_empty():
raise IndexError("Double-ended queue is empty")
raise IndexError("Deque is empty")
return self._rear.val
def to_array(self) -> list[int]:
"""Return array for printing"""
"""Return an array for printing"""
node = self._front
res = [0] * self.size()
for i in range(self.size()):
@@ -118,37 +118,37 @@ class LinkedListDeque:
return res
"""Driver Code"""
"""Driver code"""
if __name__ == "__main__":
# Initialize double-ended queue
# Initialize the deque
deque = LinkedListDeque()
deque.push_last(3)
deque.push_last(2)
deque.push_last(5)
print("double-ended queue deque =", deque.to_array())
print("Deque deque =", deque.to_array())
# Access elements
# Access an element
peek_first: int = deque.peek_first()
print("Front of the queue element peek_first =", peek_first)
print("Front element peek_first =", peek_first)
peek_last: int = deque.peek_last()
print("Rear of the queue element peek_last =", peek_last)
print("Rear element peek_last =", peek_last)
# Elements enqueue
# Enqueue elements
deque.push_last(4)
print("Element 4 rear enqueue after deque =", deque.to_array())
print("After enqueuing element 4 at the rear, deque =", deque.to_array())
deque.push_first(1)
print("Element 1 front enqueue after deque =", deque.to_array())
print("After enqueuing element 1 at the front, deque =", deque.to_array())
# Elements dequeue
# Dequeue an element
pop_last: int = deque.pop_last()
print("Rear dequeued element =", pop_last, ", rear dequeue after deque =", deque.to_array())
print("Element dequeued from the rear =", pop_last, ", after dequeuing from the rear, deque =", deque.to_array())
pop_first: int = deque.pop_first()
print("Front dequeued element =", pop_first, ", front dequeue after deque =", deque.to_array())
print("Element dequeued from the front =", pop_first, ", after dequeuing from the front, deque =", deque.to_array())
# Get the length of the double-ended queue
# Get the deque size
size: int = deque.size()
print("Length of the double-ended queue size =", size)
print("Deque size =", size)
# Check if the double-ended queue is empty
# Check whether the deque is empty
is_empty: bool = deque.is_empty()
print("Is the double-ended queue empty =", is_empty)
print("Is the deque empty =", is_empty)

View File

@@ -12,7 +12,7 @@ from modules import ListNode
class LinkedListQueue:
"""Queue based on linked list implementation"""
"""Queue implemented with a linked list"""
def __init__(self):
"""Constructor"""
@@ -21,22 +21,22 @@ class LinkedListQueue:
self._size: int = 0
def size(self) -> int:
"""Get the length of the queue"""
"""Get the queue size"""
return self._size
def is_empty(self) -> bool:
"""Check if the queue is empty"""
"""Check whether the queue is empty"""
return self._size == 0
def push(self, num: int):
"""Enqueue"""
# Add num after the tail node
node = ListNode(num)
# If the queue is empty, make both front and rear point to the node
# If the queue is empty, make both the head and tail point to this node
if self._front is None:
self._front = node
self._rear = node
# If the queue is not empty, add the node after the tail node
# If the queue is not empty, add this node after the tail node
else:
self._rear.next = node
self._rear = node
@@ -45,19 +45,19 @@ class LinkedListQueue:
def pop(self) -> int:
"""Dequeue"""
num = self.peek()
# Delete head node
# Remove the head node
self._front = self._front.next
self._size -= 1
return num
def peek(self) -> int:
"""Access front of the queue element"""
"""Access the front element"""
if self.is_empty():
raise IndexError("Queue is empty")
return self._front.val
def to_list(self) -> list[int]:
"""Convert to list for printing"""
"""Convert to a list for printing"""
queue = []
temp = self._front
while temp:
@@ -66,32 +66,32 @@ class LinkedListQueue:
return queue
"""Driver Code"""
"""Driver code"""
if __name__ == "__main__":
# Initialize queue
# Initialize the queue
queue = LinkedListQueue()
# Elements enqueue
# Enqueue elements
queue.push(1)
queue.push(3)
queue.push(2)
queue.push(5)
queue.push(4)
print("queue =", queue.to_list())
print("Queue queue =", queue.to_list())
# Access front of the queue element
# Access the front element
peek: int = queue.peek()
print("Front of the queue element front =", peek)
print("Front element peek =", peek)
# Element dequeue
# Dequeue an element
pop_front: int = queue.pop()
print("Dequeued element pop =", pop_front)
print("After dequeue queue =", queue.to_list())
print("Dequeued element pop_front =", pop_front)
print("After dequeuing, queue =", queue.to_list())
# Get the length of the queue
# Get the queue size
size: int = queue.size()
print("Length of the queue size =", size)
print("Queue size =", size)
# Check if the queue is empty
# Check whether the queue is empty
is_empty: bool = queue.is_empty()
print("Is the queue empty =", is_empty)

View File

@@ -12,7 +12,7 @@ from modules import ListNode
class LinkedListStack:
"""Stack based on linked list implementation"""
"""Stack implemented with a linked list"""
def __init__(self):
"""Constructor"""
@@ -20,11 +20,11 @@ class LinkedListStack:
self._size: int = 0
def size(self) -> int:
"""Get the length of the stack"""
"""Get the stack size"""
return self._size
def is_empty(self) -> bool:
"""Check if the stack is empty"""
"""Check whether the stack is empty"""
return self._size == 0
def push(self, val: int):
@@ -42,13 +42,13 @@ class LinkedListStack:
return num
def peek(self) -> int:
"""Access top of the stack element"""
"""Access the top element"""
if self.is_empty():
raise IndexError("Stack is empty")
return self._peek.val
def to_list(self) -> list[int]:
"""Convert to list for printing"""
"""Convert to a list for printing"""
arr = []
node = self._peek
while node:
@@ -58,32 +58,32 @@ class LinkedListStack:
return arr
"""Driver Code"""
"""Driver code"""
if __name__ == "__main__":
# Initialize stack
# Initialize the stack
stack = LinkedListStack()
# Elements push onto stack
# Push elements onto the stack
stack.push(1)
stack.push(3)
stack.push(2)
stack.push(5)
stack.push(4)
print("stack =", stack.to_list())
print("Stack stack =", stack.to_list())
# Access top of the stack element
# Access the top element
peek: int = stack.peek()
print("Top of the stack element peek =", peek)
print("Top element peek =", peek)
# Element pop from stack
# Pop an element from the stack
pop: int = stack.pop()
print("Popped element pop =", pop)
print("After pop stack =", stack.to_list())
print("After popping, stack =", stack.to_list())
# Get the length of the stack
# Get the stack size
size: int = stack.size()
print("Length of the stack size =", size)
print("Stack size =", size)
# Check if it is empty
# Check whether it is empty
is_empty: bool = stack.is_empty()
print("Is the stack empty =", is_empty)

View File

@@ -6,34 +6,34 @@ Author: Peng Chen (pengchzn@gmail.com)
from collections import deque
"""Driver Code"""
"""Driver code"""
if __name__ == "__main__":
# Initialize queue
# In Python, we generally use the double-ended queue class deque as a queue
# Although queue.Queue() is a proper queue class, it is not very convenient to use
# Initialize the queue
# In Python, we generally use the deque class as a queue
# Although queue.Queue() is a dedicated queue class, deque is more convenient for this example
que: deque[int] = deque()
# Elements enqueue
# Enqueue elements
que.append(1)
que.append(3)
que.append(2)
que.append(5)
que.append(4)
print("queue que =", que)
print("Queue que =", que)
# Access front of the queue element
# Access the front element
front: int = que[0]
print("Front of the queue element front =", front)
print("Front element front =", front)
# Element dequeue
# Dequeue an element
pop: int = que.popleft()
print("Dequeued element pop =", pop)
print("After dequeue que =", que)
print("After dequeuing, que =", que)
# Get the length of the queue
# Get the queue size
size: int = len(que)
print("Length of the queue size =", size)
print("Queue size =", size)
# Check if the queue is empty
# Check whether the queue is empty
is_empty: bool = len(que) == 0
print("Is the queue empty =", is_empty)

View File

@@ -4,33 +4,33 @@ Created Time: 2022-11-29
Author: Peng Chen (pengchzn@gmail.com)
"""
"""Driver Code"""
"""Driver code"""
if __name__ == "__main__":
# Initialize stack
# Python does not have a built-in stack class, we can use list as a stack
# Initialize the stack
# Python has no built-in stack class; a list can be used as a stack
stack: list[int] = []
# Elements push onto stack
# Push elements onto the stack
stack.append(1)
stack.append(3)
stack.append(2)
stack.append(5)
stack.append(4)
print("stack =", stack)
print("Stack stack =", stack)
# Access top of the stack element
# Access the top element
peek: int = stack[-1]
print("Top of the stack element peek =", peek)
print("Top element peek =", peek)
# Element pop from stack
# Pop an element from the stack
pop: int = stack.pop()
print("Popped element pop =", pop)
print("After pop stack =", stack)
print("After popping, stack =", stack)
# Get the length of the stack
# Get the stack size
size: int = len(stack)
print("Length of the stack size =", size)
print("Stack size =", size)
# Check if it is empty
# Check whether it is empty
is_empty: bool = len(stack) == 0
print("Is the stack empty =", is_empty)