This commit is contained in:
2026-04-18 14:42:00 +05:00
commit ef77f101fa
96 changed files with 3134 additions and 0 deletions

44
labPython/lab16/task_1.py Normal file
View File

@@ -0,0 +1,44 @@
class Node:
def __init__(self, data, next=None):
self.data = data
self.next = next
def push(top, d):
return Node(d, top)
def print_stack(top):
cur = top
while cur:
print(cur.data, end=" ")
cur = cur.next
print()
top = None
while True:
try:
print("\n1 - создать стек")
print("2 - добавить элемент")
print("3 - показать стек")
print("0 - выход")
c = input(">> ")
if c == "1":
top = None
arr = list(map(int, input("Введите числа: ").split()))
for x in arr:
top = push(top, x)
elif c == "2":
d = int(input("Введите D: "))
top = push(top, d)
print("Новая вершина:", top.data if top else None)
elif c == "3":
print_stack(top)
elif c == "0":
break
except:
print("Ошибка ввода")