Warning
This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

8. Zásobník

class Stack:
 
    def __init__ (self):
 
        self.items = [] # prazdny seznam pro udzovani dat
 
    def push (self, data):
 
        self.items += [data]
 
    def pop (self):
 
        return self.items.pop()
 
    def is_empty (self):
 
        return self.items == []
 
    def size (self):
 
        return len(self.items)
 
 
s = Stack()
 
s.push (10)
s.push (30)
s.push (40)
 
while s.is_empty() is not True:
    print (s.pop())
 
text = 'TE*A*QYS***SEU****NI*O**'
 
z = Stack()
 
for x in range(len(text)):
    # print (text[x], end=' ')
    if text[x] >= 'A' and text[x] <= 'Z':
        z.push(text[x])
    if text[x] == '*':
        print(z.pop(), end='')
 
print()
 
text = '((()()))'
w = Stack()
 
for x in range(len(text)):
    if text[x] == '(':
        w.push(text[x])
    if text[x] == ')':
        print('{}-{}'.format(x, w.size()))
        if w.is_empty() or w.pop() != '(':
            print(w.is_empty())
            print('nevalidni')
 
if w.is_empty() is not True:
    print(w.is_empty())
    print('nevalidni')

courses/bab37zpr/solutions/lab08.txt · Last modified: 2019/11/19 13:55 by viteks