нерекурсивная версия:
struct node {
struct node *parent;
unsigned nchild;
struct node *child[XXX];
int data;
};
void deltree(struct node *np)
{
struct node *par;
while (np) {
/* if this node has any children, start by
** "descending" to the highest numbered child and kill that first.
*/
if (np->nchild--) {
np = np->child[np->nchild];
continue;
}
/* when we arrive here, *np has no more children left,
** so kill it, and step up to its parent
*/
par = node->parent;
// if np->child was obtained via malloc() uncomment next line
// free (np->child);
free (np);
np = par;
}
return;
}