mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-15 22:57:48 +08:00
Add ru version (#1865)
* Add Russian docs site baseline * Add Russian localized codebase * Polish Russian code wording * Update ru code translation. * Update code translation and chapter covers. * Fix pythontutor extraction. * Add README and landing page. * placeholder of profiles * Use figures of English version * Remove chapter paperbook
This commit is contained in:
39
ru/codes/python/chapter_stack_and_queue/queue.py
Normal file
39
ru/codes/python/chapter_stack_and_queue/queue.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""
|
||||
File: queue.py
|
||||
Created Time: 2022-11-29
|
||||
Author: Peng Chen (pengchzn@gmail.com)
|
||||
"""
|
||||
|
||||
from collections import deque
|
||||
|
||||
"""Driver Code"""
|
||||
if __name__ == "__main__":
|
||||
# Инициализировать очередь
|
||||
# В Python мы обычно рассматриваем двустороннюю очередь deque как очередь
|
||||
# Хотя queue.Queue() — это «настоящий» класс очереди, им не очень удобно пользоваться
|
||||
que: deque[int] = deque()
|
||||
|
||||
# Добавление элемента в очередь
|
||||
que.append(1)
|
||||
que.append(3)
|
||||
que.append(2)
|
||||
que.append(5)
|
||||
que.append(4)
|
||||
print("Очередь que =", que)
|
||||
|
||||
# Доступ к элементу в начале очереди
|
||||
front: int = que[0]
|
||||
print("Первый элемент front =", front)
|
||||
|
||||
# Извлечение элемента из очереди
|
||||
pop: int = que.popleft()
|
||||
print("Извлеченный элемент pop =", pop)
|
||||
print("que после извлечения =", que)
|
||||
|
||||
# Получение длины очереди
|
||||
size: int = len(que)
|
||||
print("Длина очереди size =", size)
|
||||
|
||||
# Проверка, пуста ли очередь
|
||||
is_empty: bool = len(que) == 0
|
||||
print("Пуста ли очередь =", is_empty)
|
||||
Reference in New Issue
Block a user