Пример #1
0
 def _balance_factor(node):
     '''
     Returns the balance factor of a node.
     '''
     if node is None:
         return 0
     return BinaryTree._height(node.left) - BinaryTree._height(node.right)
Пример #2
0
 def _balance_factor(node):
     if node is None:
         return 0
     return BinaryTree._height(node.left) - BinaryTree._height(node.right)
Пример #3
0
 def __eq__(self, t2):
     in_order1 = BinaryTree.to_list(self, 'inorder')
     in_order2 = BinaryTree.to_list(t2, 'inorder')
     return in_order1 == in_order2
from containers.BinaryTree import BinaryTree, Node


_example0 = BinaryTree()

_example1 = BinaryTree()
_example1.root = Node(1)
_example1.root.left = Node(2)
_example1.root.left.left = Node(4)
_example1.root.left.right = Node(5)
_example1.root.right = Node(3)

_example2 = BinaryTree()
_example2.root = Node(0)
_example2.root.left = Node(1)
_example2.root.left.left = Node(2)
_example2.root.left.left.left = Node(3)
_example2.root.left.left.left.left = Node(4)
_example2.root.left.left.left.left.left = Node(5)
_example2.root.left.left.left.left.left.left = Node(6)
_example2.root.left.left.left.left.left.right = Node(7)
_example2.root.left.left.right = Node(8)
_example2.root.left.left.right.left = Node(9)
_example2.root.left.left.right.right = Node(10)
_example2.root.left.right = Node(11)
_example2.root.right = Node(12)
_example2.root.right.right = Node(13)
_example2.root.right.right.right = Node(14)

_example3 = BinaryTree()
_example3.root = Node(0)
Пример #5
0
 def __eq__(self, t2):
     list1 = BinaryTree.to_list(self, 'inorder')
     list2 = BinaryTree.to_list(t2, 'inorder')
     return list1 == list2