• + 2 comments

    python3

    def mergeLists(head1, head2):
        temp=[]
        cur=head1
        while cur:
            temp.append(cur.data)
            cur=cur.next
        cur=head2
        while cur:
            temp.append(cur.data)
            cur=cur.next
        temp.sort()
        llist=SinglyLinkedList()
        for i in temp:
            llist.insert_node(i)
        return llist.head