- java.lang.Object
-
- io.github.astrapi69.tree.binary.GenericBinaryTree<T>
-
- Type Parameters:
T
- the generic type of the values
public abstract class GenericBinaryTree<T> extends java.lang.Object
The abstract classGenericBinaryTree
represents a generic binary tree. A binary tree is a recursive data structure where a binary tree node can have only 2 children. For an example see the unit tests
-
-
Field Summary
Fields Modifier and Type Field Description protected LinkedNode<T>
first
the firstLinkedNode
object is also the root object
-
Constructor Summary
Constructors Constructor Description GenericBinaryTree()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description GenericBinaryTree<T>
add(T value)
Adds the given value to the binary tree at the right positionprotected LinkedNode<T>
addRecursively(LinkedNode<T> linkedNode, T value)
Adds the given value to the binary tree at the right positionboolean
contains(T value)
Checks if the given value exists in this binary tree objectprotected boolean
containsRecursively(LinkedNode<T> linkedNode, T value)
Checks recursively if the given value exists in this binary tree objectabstract boolean
isGreater(LinkedNode<T> linkedNode, T value)
Checks if the given value is greater than the value of the givenLinkedNode
objectabstract boolean
isSmaller(LinkedNode<T> linkedNode, T value)
Checks if the given value is smaller than the value of the givenLinkedNode
object
-
-
-
Field Detail
-
first
protected LinkedNode<T> first
the firstLinkedNode
object is also the root object
-
-
Method Detail
-
isSmaller
public abstract boolean isSmaller(LinkedNode<T> linkedNode, T value)
Checks if the given value is smaller than the value of the givenLinkedNode
object- Parameters:
linkedNode
- theLinkedNode
objectvalue
- the value- Returns:
- true if the given value is smaller than the value of the given
LinkedNode
object otherwise false
-
isGreater
public abstract boolean isGreater(LinkedNode<T> linkedNode, T value)
Checks if the given value is greater than the value of the givenLinkedNode
object- Parameters:
linkedNode
- theLinkedNode
objectvalue
- the value- Returns:
- true if the given value is greater than the value of the given
LinkedNode
object otherwise false
-
addRecursively
protected LinkedNode<T> addRecursively(LinkedNode<T> linkedNode, T value)
Adds the given value to the binary tree at the right position- Parameters:
linkedNode
- theLinkedNode
objectvalue
- the value- Returns:
- the added
LinkedNode
object
-
add
public GenericBinaryTree<T> add(T value)
Adds the given value to the binary tree at the right position- Parameters:
value
- the value- Returns:
- this binary tree object so you can chain
-
containsRecursively
protected boolean containsRecursively(LinkedNode<T> linkedNode, T value)
Checks recursively if the given value exists in this binary tree object- Parameters:
linkedNode
- theLinkedNode
objectvalue
- the value- Returns:
- true if the given value exists in this binary tree object otherwise false
-
contains
public boolean contains(T value)
Checks if the given value exists in this binary tree object- Parameters:
value
- the value- Returns:
- true if the given value exists in this binary tree object otherwise false
-
-