Its easy to create a tree when you know the no of child each node has.
How do i make a program that makes a tree with arbitrary no. of children which can be specified during run time ?
I dont' want a binary tree. and i don't want to use array as it has to be fixed before run time and i don't want to use vector because it becomes very high level abstraction. i want to create a bare bone of such a tree structure... with n (defined for each node separately) at run time.
Didn't try that one out, but technically it should work. Though I'd actually rather suggest you to go for an object oriented approach, this one here is very prone to user errors.
Well, I normally don't work with those, so you might be right on that. But that's language semantics, at least when I say array I just mean a chunk of memory. As I said, I don't know if my example would work exactly like that, but I was just trying to get the idea across. In a real life situation you would have to do a few other things as well anyways, like checkin whether you actually got that new memory or not, or whether child and parent are actually distinct objects...
I actually wanted to use something more primitive as pointer to pointer or something more basic. I know i can easily do it using vector . but the purpose of this exercise is to be able to build complex tree structure without any high level functionalities.
and i think even if i use a linked list ( a full class which i completed implementing a day ago) i should be able to get it done. But i want something more primitive and more powerful than all this.
~navderm
You can represent a tree with variable, arbitrary numbers of nodes with a linked list. Each node in the list has to be able to hold either a terminal or another list. Then you can just throw in a convention: the first node of each list represents the tree node value, while the remaining nodes represent its children (which can be terminals or lists themselves).