Package dsa.iface
Interface ITree<T>
- All Known Subinterfaces:
IBinaryTree<T>
- All Known Implementing Classes:
AbstractBinaryTree
public interface ITree<T>
Interface representing a Tree data structure.
-
Method Summary
Modifier and TypeMethodDescriptionGet an Iterator to iterate over the child positions ofp
.boolean
isEmpty()
Test whether the tree is empty.boolean
isExternal
(IPosition<T> p) Test whether positionp
is external (i.e.boolean
isInternal
(IPosition<T> p) Test whether positionp
is internal (i.e.boolean
Test whether positionp
is the root of the tree.iterator()
Get an Iterator that iterates over all the elements contained in the tree's positions.Get the parent of positionp
(ornull
if the position has no parent (i.e.Get an Iterator that iterates over all the positions in the tree.Replace the element contained in a position.root()
Get the root position of the tree.int
size()
Get the size of the tree (i.e.
-
Method Details
-
root
Get the root position of the tree.- Returns:
- The position object at the tree root.
-
parent
Get the parent of positionp
(ornull
if the position has no parent (i.e. is the root).- Parameters:
p
-- Returns:
- The
IPosition
representing the parent ofp
, ornull
ifp
is the root.
-
children
Get an Iterator to iterate over the child positions ofp
.- Parameters:
p
-- Returns:
-
isInternal
Test whether positionp
is internal (i.e. has children).- Parameters:
p
-- Returns:
-
isExternal
Test whether positionp
is external (i.e. has no children).- Parameters:
p
-- Returns:
-
isRoot
Test whether positionp
is the root of the tree.- Parameters:
p
-- Returns:
true
ifp
is the root,false
otherwise.
-
size
int size()Get the size of the tree (i.e. the number of positions it contains).- Returns:
-
isEmpty
boolean isEmpty()Test whether the tree is empty.- Returns:
true
if thesize()==0
, @{code false} otherwise.
-
iterator
Get an Iterator that iterates over all the elements contained in the tree's positions.- Returns:
-
positions
Get an Iterator that iterates over all the positions in the tree.- Returns:
-
replace
Replace the element contained in a position.- Parameters:
p
- A position in the tree.e
- The new element to store inp
.- Returns:
- The element that was formerly contained in the position before replacement.
-