struct elem {
int content;
struct elem *next;
};
static struct elem * flat (struct tnode *t,
struct elem *l)
{
if (t) {
struct elem *n = malloc (sizeof (struct elem));
if (n == NULL) {
fputs ("Out of memory\n", stderr);
exit (1);
}
n->next = flat (t->right, l);
n->content = t->content;
return flat (t->right, n);
} else
return l;
}
struct elem *flatten (struct tnode *tree)
{
return flat (tree, NULL);
}