So I have managed to make a BST in Java with using an array but a friend told me he has done it with out using an array. I know roughly how he has done it here is an example(I have left out constructors and getters and setters):
class TreeNode implements Comparable<TreeNode>
{
private int value;
private TreeNode leftChild;
private TreeNode rightChild;
private TreeNode parent;
As you can see you can just link the left and the right nodes but this got me thing to how the add method would work. So far I have just initialized a new object like this:
public void add(Comparable c)
{
TreeNode node = new TreeNode(c);
}
But this leaves wondering how can I link to the previous object if I can't access it like it was in an array? and every time I go to link a object I end up adding a new one. I'm kinda confused on how to implement this method, how would you do it?