Merge two sorted linked lists

  • + 0 comments

    I'm actually just gonna post every time I see these uneditable classes that don't compile. Srsly! (C#)

    Super easy in python :(

    def mergeLists(head1, head2):
        head = SinglyLinkedListNode(0)
        end = head
        while head1 is not None or head2 is not None:
            if head1 is None or (head2 is not None and head1.data > head2.data):
                (head1, head2) = (head2, head1)
            end.next = head1
            head1 = head1.next
            end = end.next
        return head.next