user97140
0
Q:

online python to c++ compiler

class Node:
    def  __init__(self, char, desc, parent):
        self.char = char
        self.desc = desc
        self.parent = parent
        self.children = dict()
        if(not self.parent is None):
            self.parent.children[char] = self


home = Node('H','Home',None)

men = Node('M','Men',home)
women = Node('W','Women',home)
electronics = Node('E','Electronics',home)

mclothing = Node('C','Clothing',men)
maccessories = Node('A','Accessories',men)
mfootwear = Node('F','Footwear',men)

wclothing = Node('C','Clothing',women)
waccessories = Node('A','Accessories',women)
wfootwear = Node('F','Footwear',women)

computers = Node('C','Computers',electronics)
mobiles = Node('M','Mobiles',electronics)

mjeans = Node('J',"Jeans",mclothing)
mtrousers = Node('T',"Trousers",mclothing)
mshirts = Node('S',"Shirts",mclothing)


wjeans = Node('J',"Jeans",wclothing)
wtrousers = Node('T',"Trousers",wclothing)
wshirts = Node('S',"Shirts",wclothing)

#LIKE-WISE FILL REST


root = home
p_list = [home]
print(home.desc)
while(True):
    try:
        ch=input()
        if(ch==":"):
            break
        if(ch[:2]=="MB"):
            back_count = int(ch.split()[-1])
            p_list = p_list[:-back_count]
            
        elif(ch[:4]=="GOTO"):
            front_count = int(ch.split()[-1])
            p_list = p_list[:front_count]

        else:
            p_list.append(root.children[ch])

        root = p_list[-1]
        print(" > ".join([node.desc for node in p_list]))
    except Exception as e:
        print("Invalid Option")

This paste expires in <8 hours. Public IP access. Share whatever you see with others in seconds with Context.Terms of ServiceReport this
0

New to Communities?

Join the community