Ejemplo n.º 1
0
def eHTML():

    stk = stack1.LimitedStack()
    str1 = input("Enter the HTML")
    start = str1.find('<')
    while start != -1:
        end = str1.find('>', start + 1)
        if end == -1:
            return False
        tok = str1[start + 1:end]

        if not tok.startswith('/'):
            stk.stackpush(tok)
        else:
            if stk.isstackempty():
                return False
            if tok[1:] != stk.stackpop():
                return False
        start = str1.find('<', end + 1)

    return stk.isstackempty()
Ejemplo n.º 2
0
#Suppose you have three nonempty stacks R, S and T. Describe a sequence of operations that results in
##S storing all elements originally in T below of S’s original elements, with both sets of those elements in their original configuration.
###For example, if R = [1,2,3], S = [4, 5] and T = [6, 7, 8, 9], the final configuration should have R = [1, 2, 3] and S = [6, 7, 8,  9, 4, 5].

import stack1

s1 = stack1.LimitedStack()
s2 = stack1.LimitedStack()
s3 = stack1.LimitedStack()

m = int(input("Size of stack 1:"))
n = int(input("Size of stack 2:"))
o = int(input("Size of stack 3:"))

for ch1 in range(m):
    ele1 = int(input("enter elements of s1:"))
    s1.stackpush(ele1)

for ch2 in range(n):
    ele2 = int(input("enter elements of s2:"))
    s2.stackpush(ele2)

for ch3 in range(o):
    ele3 = int(input("enter elements of s3:"))
    s3.stackpush(ele3)

print(s1.data)
print(s2.data)
print(s3.data)

Ejemplo n.º 3
0
#Implement a function that reverses a list of elements
##by pushing them onto a stack in one order, and write them back to the list in reversed order.

import stack1

s = stack1.LimitedStack()
t = stack1.LimitedStack()

m = int(input("Size of stack:"))


def reverse(s, t):

    for ch in range(m):
        t.stackpush(s.stackpop())
    print(t.data)


for ch in range(m):
    ele = int(input("enter element:"))
    s.stackpush(ele)
print(s.data)

reverse(s, t)
Ejemplo n.º 4
0
 def __init__(self):
     self.data1 = s.LimitedStack()
     self.data2 = s.LimitedStack()
Ejemplo n.º 5
0
 def __init__(self):
     self.data1 = s.LimitedStack()
     self.data2 = s.LimitedStack()
     self.front = 0
     self.size = 0
Ejemplo n.º 6
0
                S.stackpush(Q.qdequeue())
            while c != 0:
                Q.qenqueue(S.stackpop())
                c -= 1
            while not Q.isqEmpty():

                S.stackpush(Q.qdequeue())
            return True

        else:
            Q.qenqueue(S.stackpop())


if __name__ == '__main__':

    S = s.LimitedStack()
    Q = q.flexiqueue()
    S.stackpush(10)
    S.stackpush(9)
    S.stackpush(40)
    S.stackpush(60)
    S.stackpush(80)
    S.stackpush(20)
    S.stackpush(13)
    S.stackpush(14)
    S.stackpush(15)
    S.stackpush(16)

    key = int(input("enter element to be searched: "))

    print(scan(key))