Ejemplo n.º 1
0
def transfer(S):
    T1 = stack_basic.LimitedStack()
    T2 = stack_basic.LimitedStack()
    while not S.isstackempty():
        T1.stackpush(S.stackpop())
    while not T1.isstackempty():
        T2.stackpush(T1.stackpop())
    while not T2.isstackempty():
        S.stackpush(T2.stackpop())
    return (S.data)
Ejemplo n.º 2
0
def sub1():
    R=stack_basic.LimitedStack()
    S=stack_basic.LimitedStack()
    T=stack_basic.LimitedStack()
    for i in range(1,4):
        R.stackpush(i)
    print (R.data)
    for i in range(4,6):
        S.stackpush(i)
    for i in range(6,10):
        T.stackpush(i)  
    print(stck6(R,S,T))
Ejemplo n.º 3
0
def reverse_1(list1):
    s1 = stack_basic.LimitedStack()
    for ele in list1:
        s1.stackpush(ele)
    list1 = []
    while not s1.isstackempty():
        list1.append(s1.stackpop())
    return (list1)
Ejemplo n.º 4
0
def evaluatehtmltag(str):
    stk = stack_basic.LimitedStack()
    start = str.index('<')
    while start != -1:
        end = str.find('>', start + 1)
        if end == -1:
            return False
        tok = str[start + 1:end]
        if not tok.startswith('/'):
            stk.stackpush(tok)
        else:
            if stk.isstackempty():
                return False
            if tok[1:] != stk.stackpop():
                return False
        start = str.find('<', end + 1)
    return stk.isstackempty()
Ejemplo n.º 5
0
#1.Implement a function with signature transfer(S,T) that transfers all elements from Stack S onto Stack T, so that that elements that starts at the top of S is the first to be inserted into T, and element at the bottom of S ends up at the top of T.
import stack_basic
import random

S = stack_basic.LimitedStack()
T = stack_basic.LimitedStack()


def signtransfer(S, T):
    yy = S.stackpush(20)
    z = S.stackpush(30)
    print(z)
    y = S.stackpop()
    a = S.stackpop()
    print(y)
    m = T.stackpush(y)
    m = T.stackpush(a)
    print(m)


signtransfer(S, T)
Ejemplo n.º 6
0
 def __init__(self):
     self.S = stack_basic.LimitedStack()
     self.T = stack_basic.LimitedStack()
Ejemplo n.º 7
0
#4.Implement a transfer function and two temporary stacks, to replace the contents of a given stack S with those same elements, but in reverse order
import stack_basic


def transfer(S):
    T1 = stack_basic.LimitedStack()
    T2 = stack_basic.LimitedStack()
    while not S.isstackempty():
        T1.stackpush(S.stackpop())
    while not T1.isstackempty():
        T2.stackpush(T1.stackpop())
    while not T2.isstackempty():
        S.stackpush(T2.stackpop())
    return (S.data)


stk = stack_basic.LimitedStack()
for i in range(1, 5):
    stk.stackpush(i)
print(transfer(stk))