コード例 #1
0
#Main method stars here. User is asked the type of Tree to use and methods are called for implementation
while True:
    _input = input("For Red-Black Tree type 0" + "\n" + "For AVL Tree type 1" + "\n" + "Your selection: ")
    if _input is not '0' and _input is not '1':
        print("Invalid, type 0 or 1" )
        continue
    else:
        break

if _input is "0": #Red-Black Tree
    tree = RedBlackTree()
    read_file()
    print("RedBlack Tree has "+ str(len(tree)) + ' nodes')
    print('and')
    print("It's height is " + str(tree._height()))

    output_file = open("RedBlack_tree.txt", "w+", encoding = 'utf-8')
    tree._write()
    output_file.close()
    
    while True:
        _inputuser = input("Please enter the depth of nodes you would like printed to file: ")
        # Checks if the input is valid for the tree.
        if int(_inputuser) >= int(tree._height()) or int(_inputuser) < 0:
             print("Depth is not valid, please choose another depth size" )
             continue
        else:
             break
#Depth of tree is read
    k=int(_inputuser)