-
Notifications
You must be signed in to change notification settings - Fork 0
/
class_stack.py
49 lines (38 loc) · 1.15 KB
/
class_stack.py
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
#zásobník
class Stack:
stack = []
length = 0
#konstr.
def __init__(self, length):
self.stack = [None] * length
self.length = length
#vložit do zásobníku
def push(self, member):
if self.stack[0] == None:
self.stack[0] = member
return True
else:
for i in range(self.length):
if self.stack[i] == None:
break
else:
print('Stack is full')
return False
for j in range(i):
self.stack[i - j] = self.stack[i - j - 1]
self.stack[0] = member
return True
#odebrat ze zásobníku
def pop(self):
ret = self.stack[0]
i = 0
while self.stack[i] != None and i < self.length - 1:
if i == self.length - 1:
self.stack[i] = None
return ret
self.stack[i] = self.stack[i + 1]
i = i + 1
self.stack[i] = None
return ret
def print(self):
print(self.stack)