def Soln04(): S = UDS.unlimStack() assert (S.isEmpty()) T = UDS.unlimStack() assert (T.isEmpty()) st = list(seed_stack(S)) assert (S.stackPeek()) return (st, transfer(S))
def soln06(): R = uds.unlimStack() S = uds.unlimStack() T = uds.unlimStack() seed_stack(R, 3) seed_stack(S, 6) seed_stack(T, 4) ans = T.data + S.data return (R.data, ans), sequence(R, S, T)
def transfer(S): T1 = UDS.unlimStack() T2 = UDS.unlimStack() while not S.isEmpty(): T1.push(S.pop()) while not T1.isEmpty(): T2.push(T1.pop()) while not T2.isEmpty(): S.push(T2.pop()) return S.data
def test_stack_empty(): stk = UDS.myStack() ustk = UDS.unlimStack() assert (stk.isEmpty()) assert (stk.stackLength() == 0) assert (ustk.isEmpty()) assert (ustk.stackLength() == 0)
def test_unlimStack(): ustk = UDS.unlimStack() assert (not ustk.push(random.randint(1, 50))) assert (not ustk.push(random.randint(1, 50))) assert (ustk.stackPeek()) while not ustk.isEmpty(): assert (ustk.pop())
def reversed_list(ls): stk = uds.unlimStack() for i in range(len(ls)): stk.push(ls[i]) ls = [] while not stk.isEmpty(): ls.append(stk.pop()) return ls
def soln10(): S = uds.unlimStack() """ S.push(10) S.push(20) S.push(30) S.push(40) S.push(50) """ soln.seed_stack(S) print(S.data) print(scan(S, 26))
def parse(script): stk = uds.unlimStack() start = script.find('<') while start != -1: end = script[start:].find('>') + start print('end-->', script[end:]) tag = script[start + 1:end] print('tag-->', tag) if tag[0] != '/' and tag[-1] != '/': stk.push(tag.split(' ')[0]) elif tag[0] != '/' and tag[-1] == '/': if not validate('<' + tag + '>'): return False elif stk.stackPeek() == tag[1:]: stk.pop() script = script[end + 1:] print('script-->', script) start = script.find('<') print('start-->', '\'' + script[start:]) return stk.isEmpty()
def validate(tag): symbols = list(tag.split(' ')) stk = uds.unlimStack() ## Remove extra whitespaces from string for sym in symbols: if sym == '': symbols.remove(sym) ## check symbols of string and validate for symbol in symbols: if symbol[0] == '<' and not symbol[1] == '/': if stk.isEmpty(): stk.push(symbol) elif symbol == '=': if stk.stackPeek()[0] != '<': stk.push(symbol) elif symbol == '/>': if stk.stackPeek()[0] == '<': stk.pop() elif symbol == '>': if stk.stackPeek()[0] == '<': tmp = stk.pop() + symbol stk.push(tmp) elif symbol[0:2] == '</' and symbol[-1] == '>': if stk.stackPeek()[1:-1] == symbol[2:-1]: stk.pop() else: if stk.stackPeek() == '=': stk.pop() stk.pop() elif stk.stackPeek() == '<': tmp = stk.pop() + symbol stk.push(tmp) else: stk.push(symbol) print(stk.data) return stk.isEmpty()
def __init__(self): self.front = uds.unlimStack() self.back = uds.unlimStack()
def __init__(self): self.data = uds.unlimStack() self.tmp = uds.unlimStack()