Compare for greater node
if ( ptr1 . data < ptr2 . data ) : NEW_LINE INDENT temp . data = ptr2 . data NEW_LINE DEDENT else : NEW_LINE INDENT temp . data = ptr1 . data NEW_LINE DEDENT if ( root == None ) : NEW_LINE INDENT root = temp NEW_LINE DEDENT else : NEW_LINE INDENT ptr = root NEW_LINE while ( ptr . next != None ) : NEW_LINE INDENT ptr = ptr . next NEW_LINE DEDENT ptr . next = temp NEW_LINE DEDENT ptr1 = ptr1 . next NEW_LINE ptr2 = ptr2 . next NEW_LINE return root NEW_LINE def display ( root ) : NEW_LINE while ( root != None ) : NEW_LINE print ( root . data , " - > " , end = " ▁ " ) NEW_LINE root = root . next NEW_LINE print ( " ▁ " ) ; NEW_LINE