摘要:
顺序查找 def linear_search(li, val): for ind, v in enumerate(li): if v == val: return ind else: return None 二分查找 def binary_search(li, val): left = 0 righ 阅读全文
摘要:
code def hanoi(n, a, b, c): if n > 0: hanoi(n-1, a, c, b) print("moving from %s to %s" % (a, c)) hanoi(n-1, b, a, c) hanoi(2, 'A', 'B', 'C') 阅读全文
摘要:
cal_time.py import time def cal_time(func): def wrapper(*args, **kwargs): t1 = time.time() result = func(*args, **kwargs) t2 = time.time() print("%s r 阅读全文
摘要:
快速排序 def partition(li, left, right): tmp = li[left] while left < right: while left < right and li[right] >= tmp: #从右面找比tmp小的数 right -= 1 # 往左走一步 li[le 阅读全文
摘要:
冒泡排序 def bubble_sort(li): for i in range(len(li)-1): #第i趟 exchange = False for j in range(len(li)-i-1): if li[j] > li[j+1]: li[j], li[j+1] = li[j+1], 阅读全文
摘要:
阅读全文