Package components.binarytree
Interface BinaryTree<T>
- Type Parameters:
T
- type ofBinaryTree
labels
- All Superinterfaces:
BinaryTreeKernel<T>
,Iterable<T>
,Standard<BinaryTree<T>>
- All Known Implementing Classes:
BinaryTree1
,BinaryTreeSecondary
BinaryTreeKernel
enhanced with secondary methods.-
Method Summary
Modifier and TypeMethodDescriptionint
height()
Reports the height ofthis
.void
inOrderAssemble
(T root, BinaryTree<T> left, BinaryTree<T> right) Assembles inthis
a tree that has the same in-order traversal as a tree with root labelroot
and subtreesleft
andright
; the declaration notwithstanding, the dynamic type ofleft
andright
must be the same as the dynamic type ofthis
.replaceRoot
(T x) Replaces the root ofthis
withx
, and returns the old root.root()
Reports the root ofthis
.Methods inherited from interface components.binarytree.BinaryTreeKernel
assemble, disassemble, size
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods 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 ofthis
withx
, 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 inthis
a tree that has the same in-order traversal as a tree with root labelroot
and subtreesleft
andright
; the declaration notwithstanding, the dynamic type ofleft
andright
must 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))
-