Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def test_stack_empty():
    stk = UDS.myStack()
    ustk = UDS.unlimStack()
    assert (stk.isEmpty())
    assert (stk.stackLength() == 0)
    assert (ustk.isEmpty())
    assert (ustk.stackLength() == 0)
Ejemplo n.º 5
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())
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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))
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
 def __init__(self):
     self.front = uds.unlimStack()
     self.back = uds.unlimStack()
Ejemplo n.º 11
0
 def __init__(self):
     self.data = uds.unlimStack()
     self.tmp = uds.unlimStack()