def test_postfix_traverse(self):
        tree = BinaryNode(10)
        tree.right = BinaryNode(15)
        tree.left = BinaryNode(5)
        tree.left.left = BinaryNode(3)
        tree.left.right = BinaryNode(7)

        self.assertEqual(tree.postfix_traverse(), "3 7 5 15 10 ")
Beispiel #2
0
    def _pop_operands(self, op, node_stack, operator_stack, operand_stack):
        operand_node2 = node_stack.pop()
        operand_node1 = node_stack.pop()

        node = BinaryNode(op)
        node.left = operand_node1
        node.right = operand_node2
        node_stack.append(node)

        operand2 = operand_stack.pop()
        operand1 = operand_stack.pop()
        operand_stack.append(self._calc(op, operand1, operand2))