当前位置:网站首页>2个有序数组排序

2个有序数组排序

2022-08-09 13:07:00 论一个测试的养成

def yxsort(l1,l2):
	while True:
		try:
			l1_f = l1[0]
		except:
			return l2
		try:
			l2_f = l2[0]
		except:
			return l1
		l2_e = l2[-1]
		l1_e = l1[-1]
		if l1_e <= l2_f:
			l1.extend(l2)
			return l1
		if l2_e <= l1_f:
			l2.extend(l1)
			return l2
		if l1_e > l2_f:
			sort(l2,l1,l1_e)
			# for i,j in enumerate(l2):
			# if l1_e <= j :
			# l1.remove(l1_e)
			# l2.insert(i,l1_e)
			# break
		if l2_e > l1_f:
			sort(l1,l2,l2_e)

def sort(l1,l2,data):
	for i,j in enumerate(l1):
		if data <= j:
			l2.remove(data)
			l1.insert(i,data)
			break


if __name__ == '__main__':
	l2 = [1, 2, 3, 4, 5, 6]
	l1 = [3, 4, 5, 6, 7, 8]
	l3 = [1, 2, 3, 5, 7, 9]
	l4 = [3, 4, 5, 6, 7, 8]
	x = yxsort(l2,l1)
	print(x)
原网站

版权声明
本文为[论一个测试的养成]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_44517891/article/details/110872434