Answers for "javascript Merge Order LinkedList"

0

javascript Merge Order LinkedList

function merge (L1, L2) {
    let L3 = { data: null, next: null };
    let prev = L3;

    while (L1 != null || L2 != null) {
        if (L1 === null) {
            prev.next = L2;
            L2 = L2.next;
            continue;
        }

        if (L2 === null) {
            prev.next = L1;
            L1 = L1.next;
            continue;
        }

        if (L1.data <= L2.data) {
            prev.next = L1;
            L1 = L1.next;
        } else {
            prev.next = L2;
            L2 = L2.next;
        }

        prev = prev.next;
    }

    return L3.next;
};
Posted by: Guest on August-09-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language