Given two string, represented as linked lists (every character is a node->data in the linked list). Write a function compare() that works similar to strcmp(), i.e., it returns 0 if both strings are same, 1 if first linked list is lexicographically greater, and -1 if second is lexicographically greater.
First line of input contains number of testcases T. For each testcase, there will be 4 lines of input. First line of which contains length of first linked list and next line contains the linked list, similarly next two lines contains length and linked list respectively.
Comapare two strings represented as linked list.
The task is to complete the function compare() which compares the strings through linked list and returns 0, 1 or -1 accordingly.
1 <= T <= 100
1 <= N, M <= 100
a b a b a
a b a a
a a b
a a b
Testcase 1: String consisting of nodes of first linked list is lexicographically greater than the second one. So, the result is 1.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.