The program should insert a node that is a sum of next 2 nodes
stdin: 2->7->4->9;
stdout: 2->11->7->13->4->9;
The program returns a segmentation fault,I'm not sure what seems to be the problem.
void insert(Node * list){
if (list==NULL) {
return;
}
for(; (list->next->next)!=NULL ; list=list->next){
Node* new=(Node*)malloc(sizeof(Node));
if(new == NULL)
return;
else {
new->data= (( list->next->next )->data )+( (list->next)-> data );
new->next = list->next;
list->next = new;
list = list->next->next ;
}
}
}