Why does it show segmentation Fault for only 1 test case out of 15 test cases.
The next and the head pointers are accessible, i didn't even alter any of the in-editable pointers.
Error - Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000401364 in compare_lists (head2=,
head1=0x192f5b0) at Solution.cpp:70
line 70 while(temp->next != nullptr && temp2->next != nullptr){
bool compare_lists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2)
{
SinglyLinkedListNode* temp = head1;
SinglyLinkedListNode* temp2 = head2;
bool abc;
int i1 = 0;
int i2 = 0;
while (temp->next != nullptr && temp2->next != nullptr) {
if (temp->data == temp2->data && i1 == i2) {
++i1;
++i2;
abc = true;
temp = temp->next;
temp2 = temp2->next;
}
else {
abc = false;
temp = temp->next;
temp2 = temp2->next;
}
}
return abc;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…