I have a structure s :
struct s{
int x;
/********************************************************************
* NoOfchild doesn't represent maximum no of children for node s .
* This represent no of children node s have at any given instance .
*********************************************************************/
int NoOfChild;
s **child;
}
I would like to use ** to declare array of pointers dynamically . Node s is added one by one to array .There is any way to achieve this. This tree is going to use for FpGrowth Algorithm.
*(0)
|
_____________________________________________________________
| | |
[* (1) *(2) *(3)]
| | |
_______________ _________________ __________________________
| | | | | | | | | | | | |
[* * * *] [* * *] [* * * * * *]
** represent Node s . I don't want to declare all children of a node at the same time
i.e. I would like to add child node one by one
when ever it's required
. e.g. o is added as root then node 1 is added as child of root if it requires then node 2 is added and so on .[* * * * ] represents children of a node x .
Edit:
People are assuming NoOfChild as maximum no of a child
for a given node that's not true ,Here NoOfChild represents how many children a node have at given instance , it may vary according to requirement or time to time .
Explanation :
Initially node 0 is Initialized so it has zero(0) child .
then node 1 is added as child of node 0 so o->NoOfChild = 1 and 1 ->NoOfChild = 0 ;
then node [*] is added as child of node 1 so 0->NoOfChild = 1 and 1 ->NoOfChild = 1 ;
then 2 is added as child of node 0 so 0->NoOfChild = 2 and 1 ->NoOfChild = 1 ;
and so on .
Edit:
Finally used vector<s*> child
.
`, or even `vector– Anton Savin Sep 29 '14 at 14:32`.`.It would trigger an [undefined behavior](http://stackoverflow.com/questions/6517231/are-c-recursive-type-definitions-possible-in-particular-can-i-put-a-vectort)– Sérgio Castelani Sep 29 '14 at 15:49