Compare for greater node
if ( ptr1 . data < ptr2 . data ) temp . data = ptr2 . data ; else temp . data = ptr1 . data ; if ( root == null ) root = temp ; else { ptr = root ; while ( ptr . next != null ) ptr = ptr . next ; ptr . next = temp ; } ptr1 = ptr1 . next ; ptr2 = ptr2 . next ; } return root ; } function display ( root ) { while ( root != null ) { document . write ( root . data + " " ) ; root = root . next ; } document . write ( " " ) ; }