struct list
{
/* other data */
int effectif_class_1
int effectif_class_2
struct list *parent
struct list *child[]
}
struct list * findNode(struct list *point)
{
int i
if(point->data == data)
return point
i=0
while(point->child[i] != NULL){
if( (findNode(point->child[i])) == point->child[i])
return point->child[i]
i++
}
return NULL
}
void addNode_changeNoeud(struct list *point)
{
int i=0
while(point->child[i] != NULL)
{
point->child[i]->Noeud ++
addNode_changeNoeud(point->child[i])
i++
}
}
void addNode(struct list *point, /* data */)
{ //在point的最右端插入一个子节点
int i=0
/* 定位到最右端 */
while(point->child[i] != NULL){
i++
}
point->child[i] = (struct list *)malloc(sizeof(struct list))
/* 保存其他数据到 point->child[i]->data */
/* 更改所有父节点的 effectif_class */
struct list *tmp
tmp = point->parent
while(tmp != NULL){
tmp->effectif_class_1 = tmp->effectif_class_1 + /* effectif_class_1 */
tmp->effectif_class_2 = tmp->effectif_class_2 + /* effectif_class_2 */
tmp = tmp->parent
}
/* 插入节点后,更新编号 */
point->child[i] = point->child[i-1] + 1
addNode_changeNoeud(point)/* 这个不好说,用于更新编号Noeud的,自己理解吧... */
}
多叉树的遍历可以仿照二叉树的遍历规则我的想法是在先序遍历的时候使用一个长度不小于(稍小亦可)树深度的栈保存遍历序列,当遍历到终端结点时,栈内就形成了"从根到一个叶的走法"序列(可能不完整),输出或者保存它
计算时间依赖于问题规模