ListNode merge(ListNode a, ListNode b) {
        ListNode root = new ListNode(0); // helper node
        ListNode x = root;
        while (a != null || b != null) {
            if (a == null) {
                x.next = b;
                b = b.next;
            } else if (b == null) {
                x.next = a;
                a = a.next;
            } else if (a.val <= b.val) {
                x.next = a;
                a = a.next;
            } else {
                x.next = b;
                b = b.next;
            }
            x = x.next;
        }
        return root.next;
    }
This is mergeSort algorithm for linked list. It divides list into two halves using two (slow, fast)
pointer and sort each half.
src/problems/medium/SortList.java