【发布时间】:2017-05-22 15:23:49
【问题描述】:
所以我正在尝试使用前序遍历从二叉树创建一个链表。 我在做这件事时遇到了很多问题,我看到了一些“解决方案”,但我不喜欢它!我正在尝试一些简单的事情。
这是我到现在为止得到的代码:
typedef struct nodo {
int value;
struct nodo *left, *right;
} *ABin;
typedef struct lligada {
int value;
struct lligada *next;
} *LInt;
void preorder (ABin a, LInt * l) {
LInt r=*l,tmp;
tmp=r;
if (!a) {
*l=NULL;
}
else {
r=malloc(sizeof(struct lligada));
r->value=a->value;
r=r->next;
*l=tmp;
preorder (a->left,l);
preorder (a->right,l);
}
}
我总是得到一个空列表!
【问题讨论】:
标签: c linked-list binary-tree preorder