I need some help with trees. I want to learn how to create trees. Is there any tutorials on this?
Printable View
I need some help with trees. I want to learn how to create trees. Is there any tutorials on this?
You need to get some seeds, dig a hole in the ground and the seeds in it. What? Oh, yeah you mean a different sort of tree, sorry my mistake :rolleyes: :D
Seriously, what type of tree are you meaning?
I would have thought this query was vague. Not trees that grow from the ground, but trees with nodes and directories.
Assuming this, the most abstract tree I can think of has a root item with children (if it has any). Every item, including the root, should have a pointer to its first child item (if it has children), its last child item (if it has children), its parent, and the items that come after and before itself. Each item can have its own data structure such as the following:
You should probably find a way to link (and unlink) the items in this manner.Code:typedef struct _treeitemstruct{
struct _treeitemstruct * parent;
struct _treeitemstruct * firstchild;
struct _treeitemstruct * lastchild;
struct _treeitemstruct * prev;
struct _treeitemstruct * next;
// add other data here
}TREEITEMSTRUCT;
You should call malloc to dynamically allocate the item structures, when necessary, so they can easily be freed just by traversing the tree from the root item (which also should be allocated).
sorry about this. I meant a tree view control. Something that is used with files a lot, like in windows Explorer.