You are viewing a single comment's thread. Return to all comments →
JAVA
static SinglyLinkedListNode mergeLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) { SinglyLinkedListNode merged = new SinglyLinkedListNode(0); SinglyLinkedListNode h1 = head1; SinglyLinkedListNode h2 = head2; SinglyLinkedListNode m = merged; while(h1 != null && h2 != null) { if (h1.data < h2.data) { m.next = h1; h1 = h1.next; } else { m.next = h2; h2 = h2.next; } m = m.next; } if (h1 != null) m.next = h1; if (h2 != null) m.next = h2; return merged.next; }
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 →
JAVA