Пример #1
0
def create_tree():
    # create the binary tree
    r = BinaryTree('a')
    r.insertLeft(BinaryTree('b'))
    r.insertRight(BinaryTree('e'))

    r.getLeftChild.insertLeft(BinaryTree('e'))

    print(r.getRootVal())
    print(r.getLeftChild().getLeftChild())
Пример #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())
Пример #3
0
def create_tree():
   # create the binary tree
   r = BinaryTree('a')

   b = BinaryTree('b')
   b.insertLeft('c')
   b.insertRight('d')

   e = BinaryTree('e')
   e.insertLeft('f')
   e.insertRight('g')

   r.insertLeft(b)
   r.insertRight(e)

   print(r.getRootVal())
   print(r.getLeftChild().getLeftChild().getRootVal())
Пример #4
0
import sys
sys.path.append("../")

from tree.binary_tree import BinaryTree
"""
we will create a binary tree looks like,
         a
      /      \
     b        e
   /   \    /   \
   c   d   f     g

"""

# create the binary tree
r = BinaryTree('a')

b = BinaryTree('b')
b.insertLeft('c')
b.insertRight('d')

e = BinaryTree('e')
e.insertLeft('f')
e.insertRight('g')

r.insertLeft(b)
r.insertRight(e)

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