inorder(v) if (hasLeft(v)) inorder(left(v)) visit(v) if (hasRight(v)) inorder(right(v))
The inorder traversal is: H D L I M B E A J F K C G
binaryTreePrint() h = height(root()) bTreePrint(root(),h) bTreePrint(v,h) if (hasLeft(v)) bTreePrint(left(v),h) for (i = 0; i < (h - depth(v)); i++) print(" ") printline(v) if (hasRight(v)) bTreePrint(right(v),h)This prints out the tree, sideways:
H D L I M B E A J F K C G
class BinaryTreeNode { Object data; BinaryTreeNode leftChild; BinaryTreeNode righChild; }
Operation | Array | Linked |
size, isEmpty | O(1) | O(1) |
elements,positions | O(n) | O(n) |
replace | O(1) | O(1) |
root, parent, children, left, right | O(1) | O(1) |
hasLeft/Right, isInternal, isRoot | O(1) | O(1) |
insert | O(n) | O(1) |