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 firstLinkedNodeobject 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 positionbooleanChecks if the given value exists in this binary tree objectprotected booleancontainsRecursively(LinkedNode<T> linkedNode, T value) Checks recursively if the given value exists in this binary tree objectabstract booleanisGreater(LinkedNode<T> linkedNode, T value) Checks if the given value is greater than the value of the givenLinkedNodeobjectabstract booleanisSmaller(LinkedNode<T> linkedNode, T value) Checks if the given value is smaller than the value of the givenLinkedNodeobject
-
Field Details
-
first
the firstLinkedNodeobject 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 givenLinkedNodeobject- Parameters:
linkedNode- theLinkedNodeobjectvalue- the value- Returns:
- true if the given value is smaller than the value of the given
LinkedNodeobject otherwise false
-
isGreater
Checks if the given value is greater than the value of the givenLinkedNodeobject- Parameters:
linkedNode- theLinkedNodeobjectvalue- the value- Returns:
- true if the given value is greater than the value of the given
LinkedNodeobject otherwise false
-
addRecursively
Adds the given value to the binary tree at the right position- Parameters:
linkedNode- theLinkedNodeobjectvalue- the value- Returns:
- the added
LinkedNodeobject
-
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- theLinkedNodeobjectvalue- 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
-