c++ - Is it possible to assign a new ListNode to an already existing node of a linkedlist? -


i writing function inputs linked list associated head2 after occurrence of variable location in list associated head1. however, keep getting core dump:

void mergelists(listnode *head1, listnode *head2, const int &location){   listnode *tail1, *tail2, *run;   tail1=head1;   tail2=head2;   if(head1->pointer_next!=nullptr){     while(tail1->content!=location){       tail1=tail1->pointer_next;     }     if(head2->pointer_next!=nullptr){       while(tail2->pointer_next!=nullptr){         run=tail1->pointer_next;         tail1->pointer_next=new listnode;         tail1=tail1->pointer_next;         tail1->content=tail2->content;         tail1->pointer_next=run;         tail2=tail2->pointer_next;       }      }   }   delete tail1;   delete tail2;   delete run; } 

is there illegal operation in line 12? ran through gdb , pretty sure problem is. have tried setting pointer next nullptr produces same result. have idea core dump occurring?

there lot of issues code, can see without debugging. please post test case + error + listnode definition.

void mergelists(listnode *head1, listnode *head2, const int &location){   listnode *tail1, *tail2, *run;   tail1=head1;   tail2=head2;   if(head1->pointer_next!=nullptr){ <------ if head1 nullptr ?     while(tail1->content!=location){  <---- if tail1 nullptr ?       tail1=tail1->pointer_next;      <---- if tail1->pointer_next nullptr ?     }     if(head2->pointer_next!=nullptr){  <--- if head2 nullptr ?       while(tail2->pointer_next!=nullptr){ <--- if tail2 nullptr ?         run=tail1->pointer_next;         tail1->pointer_next=new listnode;         tail1=tail1->pointer_next;         tail1->content=tail2->content;         tail1->pointer_next=run;         tail2=tail2->pointer_next;       }      }   }   delete tail1; <---- why delete tail1 , node in list   delete tail2; <---- why delete tail2 , node in list   delete run; } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -