Package org.arakhne.afc.math.tree
Class LinkedTree<D,N extends TreeNode<D,N>>
- java.lang.Object
-
- org.arakhne.afc.math.tree.AbstractTree<D,N>
-
- org.arakhne.afc.math.tree.LinkedTree<D,N>
-
- Type Parameters:
D
- is the type of the data inside the treeN
- is the type of the tree nodes.
- All Implemented Interfaces:
Serializable
,Iterable<N>
,BroadFirstIterableTree<D,N>
,DepthFirstIterableTree<D,N>
,Tree<D,N>
public class LinkedTree<D,N extends TreeNode<D,N>> extends AbstractTree<D,N>
This is the generic implementation of a tree based on linked lists.This tree assumes that the nodes are linked with there references.
- Since:
- 13.0
- Version:
- 17.0 2020-01-04 14:41:41
- Author:
- Stéphane GALLAND
- See Also:
- Serialized Form
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- mathtree
-
-
Constructor Summary
Constructors Constructor Description LinkedTree()
Create an emtpy tree.LinkedTree(N root1)
Create a tree with the given node.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear the tree.int
computeUserDataCount()
Force the computation of the user data count.int[]
getHeights()
Replies the heights of all the leaf nodes.int
getMaxHeight()
Replies the maximal height of the tree.int
getMinHeight()
Replies the minimal height of the tree.int
getNodeCount()
Replies the count of nodes inside this tree.N
getRoot()
Replies the root of the tree.int
getUserDataCount()
Replies the count of data inside this tree.void
setRoot(N newRoot)
Set the root of the tree.-
Methods inherited from class org.arakhne.afc.math.tree.AbstractTree
broadFirstIterator, dataBroadFirstIterator, dataDepthFirstIterator, dataDepthFirstIterator, dataDepthFirstIterator, depthFirstIterator, depthFirstIterator, depthFirstIterator, isEmpty, iterator, toBroadFirstIterable, toDataBroadFirstIterable, toDataDepthFirstIterable, toDataDepthFirstIterable, toDataDepthFirstIterable, toDepthFirstIterable, toDepthFirstIterable, toDepthFirstIterable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
LinkedTree
public LinkedTree()
Create an emtpy tree.
-
LinkedTree
public LinkedTree(N root1)
Create a tree with the given node.- Parameters:
root1
- is the root.
-
-
Method Detail
-
getRoot
@Pure public N getRoot()
Description copied from interface:Tree
Replies the root of the tree.- Returns:
- the root of the tree.
-
setRoot
public void setRoot(N newRoot)
Description copied from interface:Tree
Set the root of the tree.- Parameters:
newRoot
- is the new root node.
-
clear
public void clear()
Clear the tree.Caution: this method also destroyes the links between the nodes inside the tree. If you want to unlink the root node with this tree but leave the nodes' links unchanged, please call
setRoot(null)
.
-
getNodeCount
@Pure public int getNodeCount()
Description copied from interface:Tree
Replies the count of nodes inside this tree.- Returns:
- the count of nodes inside the whole tree.
-
getUserDataCount
@Pure public int getUserDataCount()
Description copied from interface:Tree
Replies the count of data inside this tree.- Returns:
- the count of user objects inside the whole tree.
-
computeUserDataCount
public int computeUserDataCount()
Force the computation of the user data count.- Returns:
- the count of data.
-
getMinHeight
@Pure public int getMinHeight()
Description copied from interface:Tree
Replies the minimal height of the tree.- Returns:
- the height of the uppest leaf in the tree.
-
getMaxHeight
@Pure public int getMaxHeight()
Description copied from interface:Tree
Replies the maximal height of the tree.- Returns:
- the height of the lowest leaf in the tree.
-
getHeights
@Pure public int[] getHeights()
Description copied from interface:Tree
Replies the heights of all the leaf nodes. The order of the heights is given by a depth-first iteration.- Returns:
- the heights of the leaf nodes
-
-