Package dsa.impl
Class AbstractBinaryTree<T>
java.lang.Object
dsa.impl.AbstractBinaryTree<T>
- All Implemented Interfaces:
IBinaryTree<T>
,ITree<T>
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet an Iterator to iterate over the child positions ofp
.boolean
Check whether positionp
has a left child.boolean
Check whether positionp
has a right child.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 left child of positionp
.protected AbstractBinaryTree<T>.BTPosition
newPosition
(T element, AbstractBinaryTree<T>.BTPosition parent) 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.Get the right child of positionp
.root()
Get the root position of the tree.int
size()
Get the size of the tree (i.e.toString()
-
Field Details
-
root
-
size
protected int size
-
-
Constructor Details
-
AbstractBinaryTree
public AbstractBinaryTree()
-
-
Method Details
-
root
Description copied from interface:ITree
Get the root position of the tree. -
parent
Description copied from interface:ITree
Get the parent of positionp
(ornull
if the position has no parent (i.e. is the root). -
children
Description copied from interface:ITree
Get an Iterator to iterate over the child positions ofp
. -
isInternal
Description copied from interface:ITree
Test whether positionp
is internal (i.e. has children).- Specified by:
isInternal
in interfaceITree<T>
- Parameters:
p
-- Returns:
-
isExternal
Description copied from interface:ITree
Test whether positionp
is external (i.e. has no children).- Specified by:
isExternal
in interfaceITree<T>
- Parameters:
p
-- Returns:
-
isRoot
Description copied from interface:ITree
Test whether positionp
is the root of the tree. -
size
public int size()Description copied from interface:ITree
Get the size of the tree (i.e. the number of positions it contains). -
isEmpty
public boolean isEmpty()Description copied from interface:ITree
Test whether the tree is empty. -
iterator
Description copied from interface:ITree
Get an Iterator that iterates over all the elements contained in the tree's positions. -
positions
Description copied from interface:ITree
Get an Iterator that iterates over all the positions in the tree. -
replace
Description copied from interface:ITree
Replace the element contained in a position. -
left
Description copied from interface:IBinaryTree
Get the left child of positionp
.- Specified by:
left
in interfaceIBinaryTree<T>
- Parameters:
p
-- Returns:
-
right
Description copied from interface:IBinaryTree
Get the right child of positionp
.- Specified by:
right
in interfaceIBinaryTree<T>
- Parameters:
p
-- Returns:
-
hasLeft
Description copied from interface:IBinaryTree
Check whether positionp
has a left child.- Specified by:
hasLeft
in interfaceIBinaryTree<T>
- Parameters:
p
-- Returns:
true
if positionp
has a left child,false
otherwise.
-
hasRight
Description copied from interface:IBinaryTree
Check whether positionp
has a right child.- Specified by:
hasRight
in interfaceIBinaryTree<T>
- Parameters:
p
-- Returns:
true
if positionp
has a right child,false
otherwise.
-
toString
-
newPosition
protected AbstractBinaryTree<T>.BTPosition newPosition(T element, AbstractBinaryTree<T>.BTPosition parent)
-