Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Christiaan

Linked list / tree

This topic is 6920 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hiya reader, I''m currently working on an rpg, my very first working on many different parts of the game at the sametime just to keep me from being busy with the same thing all the time sorry just needed to say this ''cause I''m posting quite a few topics today on with the business... currently I was designing/thinking how to do conversation with npc''s thought it al out and I came up with the idea to store it all in a tree (binary) the only thing is how can I save all info in the tree to a file and later on rebuid the tree from the file??? I thought of using a recursive function to read and add to the tree using either inorder/postorder or the other one which I forgot at the moment but I dunno if I do it like this the rebuild tree is exactly like the original one, so before I decide to just build the whole thing and see if it work or that i wasted a whole lot of time, I thought I might ask if anyone has experience with this or perhaps know an even better or easier way to get the job done (which would be even better) chris

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Christiaan

currently I was designing/thinking how to do conversation with npc''s thought it al out and I came up with the idea to store it all in a tree (binary) the only thing is how can I save all info in the tree to a file and later on rebuid the tree from the file??? I thought of using a recursive function to read and add to the tree using either inorder/postorder or the other one which I forgot at the moment but I dunno if it will work, so before I decide to just build the whole thing and see if it work or that i wasted a whole lot of time, I thought I might ask if anyone has experience with this or perhaps know an even better or easier way (which would be even better)




It''s worth nothing that binary trees can flattened in an array.

Just associate the array index ''i'' to a tree node. Its left child will be assigned the index ''i * 2'' and its right child ''(i * 2) + 1''.

Then, you can load/save the whole tree via a single read()/write().

Hope it helps. Bye,


Karmalaa

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!