-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_basics.py
More file actions
65 lines (49 loc) · 1.27 KB
/
Copy pathstack_basics.py
File metadata and controls
65 lines (49 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Stos:
def __init__ (self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
if self.is_empty():
return None
return self.items.pop(len(self.items)-1)
def peek(self):
if self.is_empty():
return None
return self.items.pop(0)
def size(self):
return len(self.items)
def clear(self):
self.items = []
def is_empty(self):
if len(self.items) == 0:
return 1
else:
return 0
def print_stack(self):
for elem in self.items:
print(elem, end=' ')
print()
stos = Stos()
liczby = [1, 2, 3, 4, 5]
for liczba in liczby:
stos.push(liczba)
stos.print_stack()
stos.pop()
stos.print_stack()
stos.clear()
ciagi_znakow = ['abc', 'bcd', 'cde', 'def', 'efg']
for ciag in ciagi_znakow:
stos.push(ciag)
print(stos.items)
stos.pop()
print(stos.items)
stos.clear()
data = [10, 20, 30, 40, 50, 60, 70]
for num in data:
stos.push(num)
stos.print_stack()
print("Usuwanie elementu z dolu:", stos.pop())
print("Is empty?:", stos.is_empty())
print("Size:", stos.size())
print(stos.print_stack())