我想寫以下問題的代碼:雙向鏈表插入在這兩者之間
插入每對連續元素之間的元素(鄰居的總和)?
示例:如果輸入是
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