- java.lang.Object
-
- org.jgrapht.util.AVLTree.TreeNode<T>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) intheightHeight of the node(package private) AVLTree.TreeNode<T>leftLeft child of this node(package private) AVLTree.TreeNode<T>parentParent of this node(package private) AVLTree.TreeNode<T>predecessorPrevious node in the tree according to the in order traversal(package private) AVLTree.TreeNode<T>rightRight child of this node(package private) AVLTree.TreeNode<T>subtreeMaxA maximum node in the subtree rooted at this node(package private) AVLTree.TreeNode<T>subtreeMinA minimum node in the subtree rooted at this node(package private) intsubtreeSizeSize of the subtree rooted at this node(package private) AVLTree.TreeNode<T>successorNext node in the tree according to the in order traversal(package private) TvalueA value stored in this tree node
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) intgetHeight()Returns a height of this nodeAVLTree.TreeNode<T>getLeft()Returns a left child of this node(package private) intgetLeftHeight()Returns a height of the left subtree(package private) intgetLeftSubtreeSize()Returns a size of the left subtreeAVLTree.TreeNode<T>getParent()Returns a parent of this nodeAVLTree.TreeNode<T>getPredecessor()Returns a predecessor of this node according to the tree in order traversal, ornullif this node is a minimum node in the treeAVLTree.TreeNode<T>getRight()Returns a right child of this node(package private) intgetRightHeight()Returns a height of the right subtree(package private) intgetRightSubtreeSize()Returns a size of the right subtreeAVLTree.TreeNode<T>getRoot()Returns a root of the tree this node is stored inAVLTree.TreeNode<T>getSubtreeMax()Returns a maximum node stored in the subtree rooted at this nodeAVLTree.TreeNode<T>getSubtreeMin()Returns a minimum node stored in the subtree rooted at this node(package private) intgetSubtreeSize()Returns a subtree size of the tree rooted at this nodeAVLTree.TreeNode<T>getSuccessor()Returns a successor of this node according to the tree in order traversal, ornullif this node is a maximum node in the treeAVLTree.TreeNode<T>getTreeMax()Returns a maximum node stored in the treeAVLTree.TreeNode<T>getTreeMin()Returns a minimum node stored in the treeTgetValue()Returns a value stored in this node(package private) booleanisLeftChild()Returnstrueif this node is a left child of its parent,falseotherwise(package private) booleanisLeftDoubleHeavy()Returnstrueif this node is unbalanced and the left child's height is greater,false otherwise(package private) booleanisLeftHeavy()Returnstrueif the height of the left child is greater than the height of the right child(package private) booleanisRightChild()Returnstrueif this node is a right child of its parent,falseotherwise(package private) booleanisRightDoubleHeavy()Returnstrueif this node is unbalanced and the right child's height is greater,false otherwise(package private) booleanisRightHeavy()Returnstrueif the height of the right child is greater than the height of the left child(package private) voidreset()Resets this node to the default state(package private) voidsetLeftChild(AVLTree.TreeNode<T> node)Sets the left child reference of this node tonode.(package private) voidsetPredecessor(AVLTree.TreeNode<T> node)Updates the predecessor reference of this node.(package private) voidsetRightChild(AVLTree.TreeNode<T> node)Sets the right child reference of this node tonode.(package private) voidsetSuccessor(AVLTree.TreeNode<T> node)Updates the successor reference of this node.(package private) voidsubstituteChild(AVLTree.TreeNode<T> prevChild, AVLTree.TreeNode<T> newChild)Substitutes theprevChildwith thenewChild.java.lang.StringtoString()(package private) voidupdateHeightAndSubtreeSize()Updates the height and subtree size of this node according to the values of the left and right children
-
-
-
Field Detail
-
value
T value
A value stored in this tree node
-
parent
AVLTree.TreeNode<T> parent
Parent of this node
-
left
AVLTree.TreeNode<T> left
Left child of this node
-
right
AVLTree.TreeNode<T> right
Right child of this node
-
successor
AVLTree.TreeNode<T> successor
Next node in the tree according to the in order traversal
-
predecessor
AVLTree.TreeNode<T> predecessor
Previous node in the tree according to the in order traversal
-
subtreeMin
AVLTree.TreeNode<T> subtreeMin
A minimum node in the subtree rooted at this node
-
subtreeMax
AVLTree.TreeNode<T> subtreeMax
A maximum node in the subtree rooted at this node
-
height
int height
Height of the node
-
subtreeSize
int subtreeSize
Size of the subtree rooted at this node
-
-
Constructor Detail
-
TreeNode
TreeNode(T value)
Constructs a new node with thevaluestored in it- Parameters:
value- a value to store in this node
-
-
Method Detail
-
getValue
public T getValue()
Returns a value stored in this node- Returns:
- a value stored in this node
-
getRoot
public AVLTree.TreeNode<T> getRoot()
Returns a root of the tree this node is stored in- Returns:
- a root of the tree this node is stored in
-
getSubtreeMin
public AVLTree.TreeNode<T> getSubtreeMin()
Returns a minimum node stored in the subtree rooted at this node- Returns:
- a minimum node stored in the subtree rooted at this node
-
getSubtreeMax
public AVLTree.TreeNode<T> getSubtreeMax()
Returns a maximum node stored in the subtree rooted at this node- Returns:
- a maximum node stored in the subtree rooted at this node
-
getTreeMin
public AVLTree.TreeNode<T> getTreeMin()
Returns a minimum node stored in the tree- Returns:
- a minimum node stored in the tree
-
getTreeMax
public AVLTree.TreeNode<T> getTreeMax()
Returns a maximum node stored in the tree- Returns:
- a maximum node stored in the tree
-
getParent
public AVLTree.TreeNode<T> getParent()
Returns a parent of this node- Returns:
- a parent of this node
-
getLeft
public AVLTree.TreeNode<T> getLeft()
Returns a left child of this node- Returns:
- a left child of this node
-
getRight
public AVLTree.TreeNode<T> getRight()
Returns a right child of this node- Returns:
- a right child of this node
-
getHeight
int getHeight()
Returns a height of this node- Returns:
- a height of this node
-
getSubtreeSize
int getSubtreeSize()
Returns a subtree size of the tree rooted at this node- Returns:
- a subtree size of the tree rooted at this node
-
reset
void reset()
Resets this node to the default state
-
getRightHeight
int getRightHeight()
Returns a height of the right subtree- Returns:
- a height of the right subtree
-
getLeftHeight
int getLeftHeight()
Returns a height of the left subtree- Returns:
- a height of the right subtree
-
getLeftSubtreeSize
int getLeftSubtreeSize()
Returns a size of the left subtree- Returns:
- a size of the left subtree
-
getRightSubtreeSize
int getRightSubtreeSize()
Returns a size of the right subtree- Returns:
- a size of the right subtree
-
updateHeightAndSubtreeSize
void updateHeightAndSubtreeSize()
Updates the height and subtree size of this node according to the values of the left and right children
-
isLeftDoubleHeavy
boolean isLeftDoubleHeavy()
Returnstrueif this node is unbalanced and the left child's height is greater,false otherwise- Returns:
trueif this node is unbalanced and the left child's height is greater,false otherwise
-
isRightDoubleHeavy
boolean isRightDoubleHeavy()
Returnstrueif this node is unbalanced and the right child's height is greater,false otherwise- Returns:
trueif this node is unbalanced and the right child's height is greater,false otherwise
-
isLeftHeavy
boolean isLeftHeavy()
Returnstrueif the height of the left child is greater than the height of the right child- Returns:
trueif the height of the left child is greater than the height of the right child
-
isRightHeavy
boolean isRightHeavy()
Returnstrueif the height of the right child is greater than the height of the left child- Returns:
trueif the height of the right child is greater than the height of the left child
-
isLeftChild
boolean isLeftChild()
Returnstrueif this node is a left child of its parent,falseotherwise- Returns:
trueif this node is a left child of its parent,falseotherwise
-
isRightChild
boolean isRightChild()
Returnstrueif this node is a right child of its parent,falseotherwise- Returns:
trueif this node is a right child of its parent,falseotherwise
-
getSuccessor
public AVLTree.TreeNode<T> getSuccessor()
Returns a successor of this node according to the tree in order traversal, ornullif this node is a maximum node in the tree- Returns:
- successor of this node, or null if this node in a maximum node in the tree
-
getPredecessor
public AVLTree.TreeNode<T> getPredecessor()
Returns a predecessor of this node according to the tree in order traversal, ornullif this node is a minimum node in the tree- Returns:
- predecessor of this node, or null if this node in a minimum node in the tree
-
setSuccessor
void setSuccessor(AVLTree.TreeNode<T> node)
Updates the successor reference of this node. If thenodeis notnull, updates its predecessor reference as well- Parameters:
node- new successor
-
setPredecessor
void setPredecessor(AVLTree.TreeNode<T> node)
Updates the predecessor reference of this node. If thenodeis notnull, updates its successor reference as well- Parameters:
node- new predecessor
-
setLeftChild
void setLeftChild(AVLTree.TreeNode<T> node)
Sets the left child reference of this node tonode. If thenodeis notnull, updates its parent reference as well.- Parameters:
node- a new left child
-
setRightChild
void setRightChild(AVLTree.TreeNode<T> node)
Sets the right child reference of this node tonode. If thenodeis notnull, updates its parent reference as well.- Parameters:
node- a new right child
-
substituteChild
void substituteChild(AVLTree.TreeNode<T> prevChild, AVLTree.TreeNode<T> newChild)
Substitutes theprevChildwith thenewChild. If thenewChildis notnull, updates its parent reference as well- Parameters:
prevChild- either left or right child of this nodenewChild- a new child of this node
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-