我想写以下问题的代码:双向链表插入在这两者之间
插入每对连续元素之间的元素(邻居的总和)?
示例:如果输入是
12 23 34 45 for n=4
输出应为:
12 35 23 57 34 79 45
我写的代码是:
struct node *InsBet(node *head) {
node *i,*j,*t;
i=head;
while(i->next!=NULL) {
t = (node*)malloc(sizeof(node));
t->data = i->data + i->next->data;
i->next = t;t->prev = i;
t->next = i->next;i->next->prev = t;
i = i->next;
}
return head;
}
在打印时它崩溃阵列我终奌站。
我的打印程序是:
void PrintList(node *head) {
node *i;
i=head;
while(i!=NULL) {
printf("%d ",i->data);
i=i->next;
}
}
对不起可以说你的程序请做什么,你可以给更新代码。 –
仍然我的终端是现金后,你可以找到错误 –
@RamanaUday你是对的,有第二个错误 - 看我最后的编辑 – Leeor