My question is a tiny bit different from the results I found, and I haven't used Java in quite a while (novice), so I need some clarification.
Basically, I'm pretty sure my implementation is mostly correct, I just wanted to give some back story to what I was doing.
So, my real problem is that I have serialized a binary tree to a string:
1
2 3
4 5
as:
1 2 4 # # 5 # # 3 # #
where the # are just null nodes.
My problem comes when I'm trying to rebuild it from the string. I've been doing some digging for quite a few hours, but I think I'm overcomplicating it. I just need to know the simplest way to read the string as such (delimited by whitespace):
the first element is 1, so we will change that to an int and make a node with that as the element. The next is 2, so do the same, then 4. The next is a #, so we ignore that as there is no leaf, etc.
then, I need to send the remaining part of the string (minus what has already been read from the front) into a recursive call.
In summary, my question is basically "what's the easiest way to parse it as described, and send the remaining string into a recursive call?"