I'm working with BST at the moment and I'm having a few problems with my insertion method although it seems quite logical to me. After debugging, I found out that there's a problem with the assignment of the variables I used, like every time I try to insert a node, it gets inserted as a root and therefore it prints out, "duplicates not allowed" .
For this , I'm working with 4 classes respectively. The following method is in the BinarySearchTree class that extends the BinaryTree class. In the binary tree class I have a protected BinaryTreeNode and other methods for the tree traversals.
Method call from the Main :
int value;
System.out.println("Number of elements to be inserted: ");
value = input.nextInt();
for (int i = 0; i < value; i++) {
System.out.print("Enter next element ");
num = console.nextInt();
x.setNum(num);
tree.insert(x);
}
Problem was with the method call in the main method and not the inset itself.
insert? Are you actually inserting two differentDataElementobjects?