Representing a tree structure in a binary file

This is a discussion on Representing a tree structure in a binary file within the C++ Programming forums, part of the General Programming Boards category; So, my idea is this, I can have ID's (integers) representing the various types of nodes we can have.. For ...

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964

    Representing a tree structure in a binary file

    So, my idea is this, I can have ID's (integers) representing the various types of nodes we can have..

    For instance

    0 for Transformation
    1 for Geometry
    2 for Particles
    3 etc etc...

    I can have a structure that I write to the file, that contains basically, a tree.

    First we have the root, in the root structure we can have a vector of children

    Lets say the root is a 0, and it has a 1 as a child (in the vector..

    The 1 is a geometry node, which also has a particle emitter attached to it, which is a 2 in the geometry's vector of children

    So we have something that looks like this:

    a 0 with a 1 for a child
    a 1 with a 2 for a child

    Does this sound like a good way to go about it? I figure with this much information I can create a hard coded tree structure out of the information given.

    Step 1: get the root node from the file and all its children, recursively..
    create the nodes according to the ID's

    step 2: Link them together according to the information in the structure, again the ID's

    Does this sound right?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Are my thoughts that incoherant? Am I that much off target? Any ideas anyone?

    I basically need to create a tree structure in C++ code with the right elements using a file, someone has got to know!
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I'm not 100% I understand your thoughts, but I'd prolly use two ID's per node. One to identify the node and one to identify its parent (with a special value for 'no parent', meaning a root node). Saving the nodes to a file with these two ID's lets you recreate the tree as it was.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    That sounds about right..

    I guess I couldn't figure out which one was the root node if I didn't do that...
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. Binary Tree - Reading From and Writing to a File
    By Ctank02 in forum C++ Programming
    Replies: 2
    Last Post: 03-15-2008, 09:22 PM
  3. arrays vs lists? And containers in general!
    By clegs in forum C++ Programming
    Replies: 22
    Last Post: 12-03-2007, 01:02 PM
  4. Problem reading a delimited file into a binary tree
    By neolyn in forum C++ Programming
    Replies: 10
    Last Post: 12-09-2004, 06:51 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21