1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Saving Binary Tree of Strings in Correct Order

Discussion in 'Software Development' started by robobobo, Nov 30, 2011.

Thread Status:
Not open for further replies.
  1. robobobo

    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
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1029130

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice