Compare two linked lists:

#Body
"""
 Compare two linked list
 head could be None as well for empty list
 Node is defined as

 class Node(object):

   def __init__(self, data=None, next_node=None):
       self.data = data
       self.next = next_node

 return back the head of the linked list in the below method.
"""

def CompareLists(headA, headB):
    currentA=headA
    currentB=headB
    while (currentA!=None or currentB!=None):
        if currentA!=None and currentB!=None and currentA.data == currentB.data:
            currentA = currentA.next
            currentB = currentB.next
        else:
            return 0
    return 1

results matching ""

    No results matching ""