Exemplo n.º 1
0
 def main(*argv):
     "Demostration program number 5."
     print Demo5.main.__doc__
     GeneralTree.main(*argv)
     BinaryTree.main(*argv)
     NaryTree.main(*argv)
     BinarySearchTree.main(*argv)
     AVLTree.main(*argv)
     MWayTree.main(*argv)
     BTree.main(*argv)
     return 0
Exemplo n.º 2
0
 def buildTree(lo, hi):
     """
     (char, char) -> NaryTree
     Builds an N-ary tree that contains keys in the xrange from lo to hi.
     """
     mid = chr((ord(lo) + ord(hi)) / 2)
     result = NaryTree (2, mid)
     if lo < mid:
         result.attachSubtree(0,
             Application2.buildTree(lo, chr(ord(mid) - 1)))
     if hi > mid:
         result.attachSubtree(1,
             Application2.buildTree(chr(ord(mid) + 1), hi))
     return result