Merge two sorted linked lists

  • + 0 comments

    Python3 that would have been more efficient if _ _next__was implemented

    def mergeLists(head1, head2):
        node = head1
        node2 = head2
    		arr = []
        while (node is not None):
            arr.append(node.data)
            node = node.next
        while (node2 is not None):
            arr.append(node2.data)
            node2= node2.next
       
    
    arr.sort()
    sortedSLL=SinglyLinkedList()    
    for i in arr:
        sortedSLL.insert_node(i)
    return sortedSLL.head