You are viewing a single comment's thread. Return to all comments →
A easy to understand code (using extra memory to create a newNode at each Recursion Call ).
Node MergeLists(Node headA, Node headB) { Node newNode = new Node(); if(headB== null) return headA; if (headA== null) return headB; if(headA==null && headB==null) return newNode; if( headA.data<=headB.data) { newNode.data=headA.data; newNode.next=MergeLists(headA.next,headB); } else { newNode.data=headB.data; newNode.next=MergeLists(headA,headB.next); } return newNode; }
Seems like cookies are disabled on this browser, please enable them to open this website
Merge two sorted linked lists
You are viewing a single comment's thread. Return to all comments →
A easy to understand code (using extra memory to create a newNode at each Recursion Call ).