2>4>6>8>10 1>3>5>7>9 -> 1>2>3>4>5>6>7>8>9>10
#%%
from LNode import LNode, LHead,create_unordered_list
#%%
def merge_2_rise_head(head1,head2):
if head1 == None or head1.next == None:
return head2
if head2 == None or head2.next == None:
return head1
cur1 = head1.next
cur2 = head2.next
head =LHead()
cur = head
while cur1 != None and cur2 != None:
if cur1.data <= cur2.data:
cur.next = cur1
cur1 = cur1.next
else:
cur.next = cur2
cur2 = cur2.next
cur = cur.next
if cur1 == None:
cur.next = cur2
if cur2 == None:
cur.next = cur1
return head
list1 = [2,4,6,8,10]
list2 = [0,1,2,3,5,7,9]
head1 = create_unordered_list(list1)
head2 = create_unordered_list(list2)
head = merge_2_rise_head(head1,head2)
list3 = head.get_ordered_list()
print(list3)
网友评论