PDA

View Full Version : TechTree - Way to store the data?



four4swords
October 22nd, 2010, 07:52 PM
Hi,

I'm trying to make a node tree, however I can't seem to figure out the best way to store the data. Here's the tech tree I want to store.

http://img837.imageshack.us/img837/9461/techtree.gif

The first thing that comes to mind, is to store them as an array. So, an array within an array, withing another array for however many levels deep my tech trees go.

Now that would work.. if not for the centre node which has 2 parent nodes that point to it.

How else could I store this data?

Thanks

Valaran
October 22nd, 2010, 08:48 PM
Hello,

I'd use a variation of a double-linked list, with a twist on the previous and next pointer rather being an array, pointing to multiple nodes.

Naturally this might not be optimal or anything, just the way I would go for.

Heres a link for a very typical double-linked list: http://lab.polygonal.de/2007/08/13/data-structures-example-linked-lists/

If you're lazy, it wouldnt take much modification to implemement an array of pointers in the node class. (There should be a download link somewhere along the page)

four4swords
October 22nd, 2010, 10:02 PM
Thanks a lot! That really makes things a lot easier to work with!