Exemplo n.º 1
0
def main():
    if len(argv) < 2:
        print('Error: Not enough arguments')

    filename = argv[1]
    root = deserialize(filename)
    pruneTree(root)
Exemplo n.º 2
0
def main():
    if len(argv) != 3:
        print('Error : program requires two filename arguments')
        return

    try:
        s_file = argv[1]
        t_file = argv[2]

        s_root = deserialize(s_file)
        t_root = deserialize(t_file)

        sol = find_eq_sub(s_root, t_root)
        print(sol)

    except:
        print('Error : error occurred creating trees')
Exemplo n.º 3
0
def main():
    if len(argv) != 2:
        print('Error : program requires filename argument')
        return

    filename = argv[1]
    tree = deserialize(filename)

    n = find_deepest_node(tree)
    print(n.data)
Exemplo n.º 4
0
def main():
    if len(argv) != 2:
        print('Error : program requires more arguments')
        return

    # try:
    filename = argv[1]
    root = deserialize(filename)

    sol = find_depth_sum(root)
    print(sol)
Exemplo n.º 5
0
def main():
	if len(argv) != 2:
		print('Error : program requires more arguments')
		return

	try:
		filename = argv[1]
		root = deserialize(filename)

		print_by_level(root)

	except:
		print('Error : error parsing file')
Exemplo n.º 6
0
def main():
    if len(argv) != 3:
        print('Error : program requires only a filename argument')
        return

    filename = argv[1]
    out = argv[2]
    m = deserialize(filename)

    invert(m)

    m.preorder()
    m.inorder()

    serialize(m, out)
Exemplo n.º 7
0
def main():
    if len(argv) != 3:
        print('Error : not enough arguments')
        return

    try:
        filename = argv[1]
        k = int(argv[2])

        root = deserialize(filename)

        sol = find_pair(root, k)
        print(sol)

    except:
        print('Error : invalid arguments')
Exemplo n.º 8
0
def main():
    if len(argv) != 4:
        print('Error : program requires filename argument and two data arguments')
        return

    try:
        # Deserialize the tree
        filename = argv[1]
        data1 = int(argv[2])
        data2 = int(argv[3])
        root = deserialize(filename)
        root.parent = None      # this is so that root will have an attribute parent

        mark_parent(root)
        x = find_node(root, data1)
        y = find_node(root, data2)

        lca = find_lca(root, x, y)
        print('{}'.format(lca.data))

    except:
        print('Error : invalid arguments given')