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 ; } void display ( Node * root ) { while ( root != NULL ) { cout << root -> data << " - > " ; root = root -> next ; } cout << endl ; }