Non-recursive middle-order traversal of binary tree

Non-recursive in-order traversal

Non-recursive in-order traversal is similar to pre-order traversal. The only difference is that it must first move to the left subtree of the node. After the left subtree is traversed, the node will be popped out of the stack for processing.

void inOrderNonRecursive(BinaryTreeNode root){
    
    
  if(root == null){
    
    return null;}
  llStack S = new llStack();
  while(true){
    
    
    S.push(root);
    root = root.getLeft();
  }
  if(stack.isEmpty()){
    
    
    break;
  }
  root = (BinaryTreeNode)S.pop();
  System.out.println(root.getData());
  root = root.getRight();
  }
  return;
}

Guess you like

Origin blog.csdn.net/weixin_37632716/article/details/109521493