Untitled

 avatar
unknown
plain_text
9 months ago
754 B
2
Indexable
function sortList(head: ListNode | null): ListNode | null {
    let node1 = head;
    let dem = 0;
    while (node1) {
        dem++;
        node1 = node1.next;
    }

    const mergeSort = (node, count) => {

        if (count == 1) { return  }
        let midle = Math.floor((count+1) / 2);
        
        let nd = node;
        let list1 = node;
        let list2 = null;
        let cnt = 0;
        while (nd) {
            cnt++;
            if (cnt == midle) {
                list2 = nd.next;
                nd.next = null;
            }
            nd = nd.next;
        }
        console.log(midle, list1, list2);

        mergeSort(list1, midle);
        // mergeSort(list2, count-midle);
    }
    mergeSort(head, dem);
    return null;
}
Editor is loading...
Leave a Comment