Hi all,
I am having trouble getting a tree to and from a text file.
The text file will hold questions and animals. Each node should hold one question and one animal.
So if you can imagine:
Does it have 4 legs?
/ \
Does it purr? Does it swim?
/ \ / \
Cat Dog fish NULL
yes being left and no being right.
That is the tree that is created. How would that get read into a file. How can I say in the text file "Don't go down any further past 'does it purr', go back to the right node and put the new node there".
So the file will be saved and can be read back into another run of the program.
How can i reconstruct this tree without knowing what it looked like before.
I hope this makes sense. It's doing my head in trying to think about it.
Ok so what i was thinking was add the nodes in sequence. so the text file would be
Does it have 4 legs?
Does it purr?
Cat
Dog
Does it swim?
fish
Does this require recursive functions?
Now that i think about it that ^above way would work right?
maybe just one node with 'data' and if ends in a question mark its a question and has more branches.
Any thoughts? ideas?
Thanks