• + 0 comments

    Solution in C

    bool compare_lists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) {
            SinglyLinkedListNode* curr1 = head1;
            SinglyLinkedListNode* curr2 = head2;
    
            if (head1 == NULL && head2 == NULL) {return true;}
            if (head1 == NULL || head2 == NULL) {return false;}
    
            while (curr1 != NULL && curr2 != NULL) {
                    if (curr1->data != curr2->data) {
                            return false;
                    }
    
                    curr1 = curr1->next;
                    curr2 = curr2->next;
            }
    
    return (curr1 == NULL && curr2 == NULL);
    

    }