Reputation: 31
I have to create a tree that can have up to n subnodes for each node (i.e its not a binary tree).
How do I do it?
Upvotes: 3
Views: 2845
Reputation: 59811
GLib provides an implementation of N-ary trees. If you can't use glib you should look for another library that suits your needs or roll your own N-ary tree. In a simple version a node would contain a linked list or array with pointers to further nodes.
Upvotes: 0
Reputation: 1500555
Instead of having something like this:
Node* left;
Node* right;
which you would normally do for a binary tree, you can do something like:
Node** children;
int size;
then malloc
the appropriate size for the number of pointers.
Upvotes: 2
Reputation: 639
You are looking for n-ary trees - http://oopweb.com/Algorithms/Documents/PLDS210/Volume/n_ary_trees.html The creation should be pretty simple from the information in this and other links (in google).
Upvotes: 2