Linked list / tree

Started by
0 comments, last by Christiaan 23 years, 11 months ago
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
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

---[home page] [[email=karmalaa@inwind.it]e-mail[/email]]

This topic is closed to new replies.

Advertisement