class Node(object):
def __init__(self,val=None):
self.next = None
self.val = val
def PrintCommonPart(head1,head2):
if head1 == None or head2 == None:
return
print('Common Part:',end='')
while head1 != None and head2 != None:
if head1.val < head2.val:
head1 = head1.next
elif head1.val>head2.val:
head2 = head2.next
else:
print(head2.val,end=' ')
head1 = head1.next
head2 = head2.next
print()
类似外排的方式打印