これはポインタへのポインタであり、その場合は のリストとして使用されているようですstruct exp
。
それぞれstruct exp
に、その「親」への参照と、 children のリストへのポインタがありますstruct exp
。
typedef struct exp{
int x;
struct exp *parent;
struct exp **children;
} element;
// create ROOT elemnt
element * root = (element*) malloc(sizeof(element)); //alocate mem. for 1 element
「ルート」を取得したら、子を追加できます。以下は疑似コードです
for 1 to 10{
child = new element;
child->parent = root; // tell the child who is his parent
addToRoot( root , child); // call a function that inserts elemnts to root
}
したがってroot
、10 個の要素のリストが必要です。
_______________ _______________
| | (children) | | - (parent) points to struct exp, root
| root | - points to list of struct exp -> | child 0 |
| | | | - (children) points to null; // if it's empty
_______________ _______________
_______________
| | - (parent) points to struct exp, root
| child 1 |
| | - (children) points to null; // if it's empty
_______________
_______________
| | - (parent) points to struct exp, root
| child 2 |
| | - (children) points to null; // if it's empty
_______________
_______________
| | - (parent) points to struct exp, root
| child 3 |
| | - (children) points to null; // if it's empty
_______________
.
.
.
_______________
| | - (parent) points to struct exp, root
| child 9 |
| | - (children) points to null; // if it's empty
_______________
みたいな… 役に立ちましたか?