Module gen.tree

Class GenericBinaryTree<T>

  • Type Parameters:
    T - the generic type of the values

    public abstract class GenericBinaryTree<T>
    extends java.lang.Object
    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
    • Constructor Detail

      • GenericBinaryTree

        public GenericBinaryTree()
    • Method Detail

      • isSmaller

        public abstract boolean isSmaller​(LinkedNode<T> linkedNode,
                                          T value)
        Checks if the given value is smaller than the value of the given LinkedNode object
        Parameters:
        linkedNode - the LinkedNode object
        value - 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 given LinkedNode object
        Parameters:
        linkedNode - the LinkedNode object
        value - 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 - the LinkedNode object
        value - 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 - the LinkedNode object
        value - 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