0

I keep receiving an error when I'm trying to implement a node with generic data types. the node must be able to take an int input as well as a fraction input. what am i doing wrong? The compiler says that "method Node(A) is undefined for class BinarySearchtree

    //creates a generic binary search tree class
public class BinarySearchTree<A> {

    //the root of the node, which is the middle value
    Node root;

    //this constructor will add a node
    public void addNode(A userNumber){

        Node<A> newNode = Node<A>(A userNumber);

    }//end addNode





    public class Node<T>{
        //this generic variable will become the user input either int or fraction
        private T number;

        //nodes that will become the left of right child of a parent node
        Node<T> leftChild;
        Node<T> rightChild;

        //a node constructor that will take a generic input
        Node(T number){
            this.number = number;
        }//end node constructor
    }//end the Node class



}//end binary search tree
Fizzy
  • 21
  • 4

1 Answers1

0

Instead of

    Node<A> newNode = Node<A>(A userNumber);

use

    Node<A> newNode = new Node<A>(A userNumber);

You don't have any method Node which the compiler gladly tells you about.

Vlad Stryapko
  • 1,035
  • 11
  • 29
  • oh my goodness, how could i forget the "new". such a simple mistake, thank you so much, im still pretty new to coding – Fizzy Jul 06 '17 at 01:16