Linked list hackerrank solution in C++

Problem Statement :

Youre given the pointer to the head nodes of two linked lists. Compare the data in the nodes of the linked lists to check if they are equal. If all data attributes are equal and the lists are the same length, return 1. Otherwise, return 0. Example: list1=1->2->3->Null list2=1->2->3->4->Null The two lists have equal data attributes for the first 3 nodes. list2 is longer, though, so the lists are not equal. Return 0. Function Description: Complete the compare_lists function in the editor below. compare_lists has the following parameters: 1. SinglyLinkedListNode llist1: a reference to the head of a list 2. SinglyLinkedListNode llist2: a reference to the head of a list Returns: int: return 1 if the lists are equal, or 0 otherwise Input Format: The first line contains an integer t, the number of test cases. Each of the test cases has the following format: The first line contains an integer n, the number of nodes in the first linked list. Each of the next n lines contains an integer, each a value for a data attribute. The next line contains an integer m, the number of nodes in the second linked list. Each of the next m lines contains an integer, each a value for a data attribute. Constraints: 1. 1<=t<=10 2. 1<=n,m<=1000 3. 1<=list1[i], list2[i]<=1000