二叉树的非递归中序遍历

非递归中序遍历

非递归中序遍历类似于前序遍历,唯一的区别是,首先要移动到结点的左子树,成左子树的遍历后,再将结点出栈进行处理

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;
}

猜你喜欢

转载自blog.csdn.net/weixin_37632716/article/details/109521493