Beispiel #1
0
def main():
    if len(argv) < 2:
        print('Error: Not enough arguments')

    filename = argv[1]
    root = deserialize(filename)
    pruneTree(root)
Beispiel #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')
Beispiel #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)
Beispiel #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)
Beispiel #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')
Beispiel #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)
Beispiel #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')
Beispiel #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')