随笔分类 - python实现算法学习
摘要:from random import Random def quick_sort(arr): if len(arr) > 1: qsort(arr, 0, len(arr) - 1) def qsort(arr, start, end): base = arr[start] pl = start pr = end whi...
阅读全文
摘要:l = [1, 4, 5, 2, 9, 7, 3] for i in range(len(l)-1): for j in range(len(l)-1-i): #我们每循环一次都会将最大的数推到最右边,所以需要将最右边排好的数拿走 if l[j] > l[j+1]:#前一个数与后一个数依次比较,直到将最大的数推到右边 l[j], l[j+1] = ...
阅读全文
摘要:import os filePath = "/Users/busensei/wzy/filePath/" def read(filePath, n): it = os.listdir(filePath) # 打开文件夹 for el in it: # 拿到路径 fp = os.path.join(filePath, el) # 获取到绝...
阅读全文
摘要:Python3 多继承的MRO算法选择。MRO(Method Resolution Order):方法解析顺序。 Python3 只保留了C3算法! C3算法解析: 1.C3算法解析 C3算法:MRO是一个有序列表L,在类被创建时就计算出来了。 L(Child(Base1, Base2)) = [Child + merge(L(Base1), L(Base2), Base1Base2)] L...
阅读全文
摘要:#方法0.5--- lst1 = [1, 3, 7, 9, 12] lst2 = [4, 8, 9, 13, 15, 19] def merge(a, b): c = [] h = j = 0 while j len(lst2) else 0 while lst1 and lst2: if lst1[0] < lst2[0]: lst3.appe...
阅读全文
摘要:list_1 = [] #先建一个空链表 print('输入排序个数:') n = int(input()) #接收输入个数 for i in range(n): a = input() list_1.append(a) #将这n个数都存入链表 Lenth = len(list_1) for i in range(Lenth - 1): Min = ...
阅读全文
摘要:import randomdef insert_sort(li): for i in range(1, len(li)): j = i - 1 tmp = li[i] while j >= 0 and li[j] > tmp: li[j+1] = li[j] j -= 1 li...
阅读全文
浙公网安备 33010602011771号