Package components.binarytree
Interface BinaryTree<T>
- Type Parameters:
T- type ofBinaryTreelabels
- All Superinterfaces:
BinaryTreeKernel<T>,Iterable<T>,Standard<BinaryTree<T>>
- All Known Implementing Classes:
BinaryTree1,BinaryTreeSecondary
BinaryTreeKernel enhanced with secondary methods.-
Method Summary
Modifier and TypeMethodDescriptionintheight()Reports the height ofthis.voidinOrderAssemble(T root, BinaryTree<T> left, BinaryTree<T> right) Assembles inthisa tree that has the same in-order traversal as a tree with root labelrootand subtreesleftandright; the declaration notwithstanding, the dynamic type ofleftandrightmust be the same as the dynamic type ofthis.replaceRoot(T x) Replaces the root ofthiswithx, and returns the old root.root()Reports the root ofthis.Methods inherited from interface components.binarytree.BinaryTreeKernel
assemble, disassemble, sizeMethods inherited from interface java.lang.Iterable
forEach, iterator, spliteratorMethods inherited from interface components.standard.Standard
clear, newInstance, transferFrom
-
Method Details
-
root
Reports the root ofthis.- Returns:
- the root entry of
this - Aliases:
- reference returned by
root - Requires:
this /= empty_tree- Ensures:
there exists left, right: binary tree of T (this = compose(root, left, right))
-
replaceRoot
Replaces the root ofthiswithx, and returns the old root.- Parameters:
x- the new root- Returns:
- the old root
- Aliases:
- reference
x - Updates:
this- Requires:
this /= empty_tree- Ensures:
there exists left, right: binary tree of T (#this = compose(replaceRoot, left, right) and this = compose(x, left, right))
-
height
int height()Reports the height ofthis.- Returns:
- the height
- Ensures:
height = ht(this)
-
inOrderAssemble
Assembles inthisa tree that has the same in-order traversal as a tree with root labelrootand subtreesleftandright; the declaration notwithstanding, the dynamic type ofleftandrightmust be the same as the dynamic type ofthis.- Parameters:
root- the root labelleft- the left subtreeright- the right subtree- Aliases:
- reference
root - Updates:
this- Clears:
left, right- Ensures:
IN_ORDER(this) = IN_ORDER(compose(root, #left, #right))
-