defmergesort(a,b):
c =[]
len1 =len(a)
len2 =len(b)
j,i =0,0while i < len1 and j < len2:if a[i]> b[j]:
c.append(b[j])
j +=1else:
c.append(a[i])
i +=1while i < len1:
c.append(a[i])
i +=1while j < len2:
c.append(b[j])
j +=1return c
defseparateList(q, first, last):if first < last:
mid =int((first + last)/2)
separateList(q, first, mid)
separateList(q, mid+1, last)
a = q[first:mid+1]
b = q[mid+1:last+1]
c = mergesort(a, b)
start = first
for i in c:
q[start]= i
start +=1return q
有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?
defrandom_number(number):
w =0for i inrange(1, number):for n inrange(1, number):for m inrange(1, number):if i != n and n != m and i != m:print("{}{}{}".format(i, n, m))
w +=1print("total:{}".format(w))
单链表反转
defreverse_list(list_input):
relist=[]for i inrange(len(list_input)):
relist.append(list_input.pop())return relist