Class GenericBinaryTree<T>
java.lang.Object
io.github.astrapi69.gen.tree.binary.GenericBinaryTree<T>
- Type Parameters:
T
- the generic type of the values
The abstract class
GenericBinaryTree
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
FieldsModifier and TypeFieldDescriptionprotected LinkedNode<T>
the firstLinkedNode
object is also the root object -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds 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
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 Details
-
first
the firstLinkedNode
object is also the root object
-
-
Constructor Details
-
GenericBinaryTree
public GenericBinaryTree()
-
-
Method Details
-
isSmaller
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
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
Adds the given value to the binary tree at the right position- Parameters:
linkedNode
- theLinkedNode
objectvalue
- the value- Returns:
- the added
LinkedNode
object
-
add
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
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
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
-