Ejemplo n.º 1
0
 def iterative_postorder_walk(self):
   explored = queue()
   explore_stack = stack()
   current = self.root
   current = self.postorder_dive(current, explore_stack, explored)
   while explore_stack.len() > 0:
     tmp = explore_stack.pop()
     if tmp.left.isNull != True:
       current = self.postorder_dive(tmp.left, explore_stack, explored)
   return explored.data[::-1]
Ejemplo n.º 2
0
    def iterative_inorder_walk(self):
        explored = queue()
        explore_stack = stack()
        current = self.root
        current = self.inorder_dive(current, explore_stack, explored)

        while explore_stack.len() > 0:
            tmp = explore_stack.pop()
            explored.insert(tmp.val)
            if tmp.right is not None:
                current = self.inorder_dive(tmp.right, explore_stack, explored)
        return explored.data