Data Structure - binary sort tree traversal

Preorder

  • Preorder is what we often sayLeft - root - Right
  • This binary sort tree traversal may be sequentially output each subnode
public void printTree(){
   if(isEmpty())
        System.out.println("Empty tree");
    else
        printTree(root);
}

public void printTree(BinaryNode<T> t){
    printTree(t.left);
    System.out.println(t.element);
    printTree(t.right);
}

Postorder

  • Postorder is what we often sayLeft - Right - root
  • It is used generically herein using the calculated height of the book.
public int height(BinaryNode<T> t){
	    if(t == null)
	         return -1;
	     else
	         return Math.max(height(t.left),height(t.right))+1;
    }
}

Preorder

  • Postorder is what we often say that the root == - left - right ==
  • The current node process before the child node.
Published 134 original articles · won praise 91 · views 160 000 +

Guess you like

Origin blog.csdn.net/weixin_44588495/article/details/102791374