Ejemplo n.º 1
0
def create_tree():
   # create the binary tree
   r = BinaryTree('a')
   r.insertLeft('b')
   r.insertRight('e')

   r.getLeftChild().insertLeft('c')
   r.getLeftChild().insertRight('d')

   r.getRightChild().insertLeft('f')
   r.getRightChild().insertRight('g')

   print(r.getRootVal())
   print(r.getLeftChild().getRootVal())
   print(r.getLeftChild().getLeftChild().getRootVal())
Ejemplo n.º 2
0
def create_tree():
   # create the binary tree
   r = BinaryTree('book')
   r.insertLeft('chapter1')
   r.insertRight('chapter2')

   r.getLeftChild().insertLeft('section1.1')
   r.getLeftChild().insertRight('section1.2')

   r.getRightChild().insertLeft('section2.1')
   r.getRightChild().insertRight('section2.2')

   print(r.getRootVal())
   print(r.getLeftChild().getRootVal())
   print(r.getLeftChild().getLeftChild().getRootVal())