使用 Python 的 LifoQueue
在這個練習中,你會使用 Python 的 LifoQueue()。你會建立一個名為 my_book_stack 的堆疊,將書加入其中並從中移除。
本練習屬於課程
Data Structures and Algorithms in Python
練習說明
- 匯入包含 Python
LifoQueue()的模組。 - 建立一個無上限的
LifoQueue()。 - 將一個元素加入堆疊。
- 從堆疊移除一個元素。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the module to work with Python's LifoQueue
import ____
# Create an infinite LifoQueue
my_book_stack = queue.____(____)
# Add an element to the stack
my_book_stack.____("Don Quixote")
# Remove an element from the stack
my_book_stack.____()