suppose list 'A' is 1->3->5 and list 'B' is 4->6->7 how would you handle merging them with condition that they need to be sorted after merging I would like to share my view about this, please let me know if it needs improvement,
i) Compare first node of 'B' with each node of 'A'
while A.val<B.val
A=A.next
We get 'A' pointing to node whose value is lesser than node of 'B'
ii) As per the example, intent is to store '4' in '3' 's reference and prior to that store '3' 's reference in a temp
iii) The same will have to be done for nodes in 'A', as in '5' will have to be stored between 4 and 6
Please review this and help me in improvising