Saving Binary Tree of Strings in Correct Order

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

robobobo

Thread Starter
Joined
Apr 27, 2008
Messages
167
Hi Guys,

I've been working on creating a binary tree that's going to work kind of like the game 20 questions (except there will probably be a lot more than 20 questions after a while)

Basically I've managed to get my classes together so that I think it will work apart from one bit.

The way the program works is it will ask the user a question(current node), if the user answers yes, it will move on and ask if it is xyz (currentnode.right) but if the user answers no, then it will go left which will ask another question if there's one stored in that node, if not and the node = null, then it will ask the user to say what they were thinking of. Then enter a question they would answer yes or no to for that item.

This question and answer then get added to the binary tree in appropriate positions. Essentially the tree grows each time it's played.

The problem is, when the user exits, and re-enters, all the new questions and answers it gained will be lost. So I have to persist the node to the disk.

This is where I'm having trouble.

I can save the binary tree easily enough in order when it's populated by ints, but since it's populated by Strings I can't save it and repopulate it in the normal way.

Has anyone any ideas how I can save and then repopulate the string values in the nodes so that they go back into their correct positions when the programs loaded again?

Any help would be much much appreciated!

thanks
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top