我无法弄清楚如何让函数递归地返回新列表的“头”。它们附加得很好,但递归地我无法弄清楚如何“保存我的位置”可以这么说。
struct node {
int value;
node *next;
};
node* append(node *&L1, node *L2)
{
if(L1->next == NULL) {
L1->next = L2;
return L1;
}
else if(L2 == NULL)
return L1;
else
return append(L1->next, L2);
}
void main()
{
node *a, *b, *c, *d;
a=new node;
b=new node;
c=new node;
d=new node;
a->value = 4;
a->next = b;
b->next = NULL;
b->value = 7;
c->next = d;
c->value = 12;
d->next = NULL;
d->value = 8;
append(a,c);
}