0

Usually they have only two, but I need to make an object were there are a random number of pointers. To represent this image enter image description here

Using what I know I made this:

struct tree{
    string name;
    list<struct pointer> pointers,

    tree(int x){
        name= x;
        pnext=null;
    }
} root1;

struct pointer{
    struct tree *pnext;
};

A tree or object with a list of pointers and the structure for the pointers, but I doesn´t seem right. How can I make a tree with a random number of pointers? (I should say what is wrong with but I don´t een know were to start, sorry)

sietschie
  • 7,425
  • 3
  • 33
  • 54

1 Answers1

0

try this:

#include <vector>

struct person {
    string name;

    vector<person> children;

    person(string iName, vector<person> iChildren) {
        name = iName;
        children = iChildren;
    }
}

This way, each person has a name, and a vector with all of it's children in it.

xX Eman Xx
  • 111
  • 5