Created
September 22, 2019 19:12
-
-
Save wenweixu/73bac7a24322059385629724a89146df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mergeLists(head1, head2): | |
llist3 = SinglyLinkedList() | |
while head1 or head2: | |
if head1 == None: | |
llist3.insert_node(head2.data) | |
head2 = head2.next | |
elif head2 == None: | |
llist3.insert_node(head1.data) | |
head1 = head1.next | |
elif head1.data >= head2.data: | |
llist3.insert_node(head2.data) | |
head2 = head2.next | |
elif head2.data > head1.data: | |
llist3.insert_node(head1.data) | |
head1 = head1.next | |
return llist3.head |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment