Here is a quick summary of what I'm trying to do:
I have a file with formatted like this
Does it have legs?
Dog
Fish
and the resulting tree for it should look like this
Does it have legs?
/ \
Dog Fish
and I'm trying to write a function that takes in a Scanner object that should already be tied to the data file and create a tree from this data that is already listed in Preorder fashion. I know tha recurison is probably the best way to go about this but everything that I have written hasn't worked. Also, I cant really figure out a way to use recursion when the function is taking in a Scanner I dont know how it would work.
Any help would be greatly appreciated.
Here is what I have now:
public BinaryTree<String> readTree(Scanner data)
{
BinaryTree<String> temp = new BinaryTree<String>();
temp.attachLeft(data.next());
temp.attachRight(data.next());
return temp;
}
I know this function wont go through the whoel file, but I've tried many loops but I cant figure out how to get it to work so I'm convinced that I need to figure out how to make it recursive
(yes I know that everything that can be done through recursion can be done with a loop)