摘要:
# coding:utf-8#[17, 20, 26, 31, 44, 54, 55, 77, 93]#mid = n/2##[17, 20, 26, 31]#mid = n/2 def binary_search(alist, item): """二分查找,遞歸""" n = len(alist) 阅读全文
摘要:
必须要掌握“快速排序” 阅读全文
摘要:
# coding:utf-8 def merge_sort(alist): """歸幷排序""" n = len(alist) if n <= 1: return alist mid = n//2 # left 採用歸幷排序後形成的有序的新的列表 left_li = merge_sort(alist 阅读全文
摘要:
# coding:utf-8 def quick_sort(alist, first, last): """快速排序""" if first >= last: return mid_value = alist[first] low = first high = last while low < hi 阅读全文
摘要:
# coding:utf-8 def shell_sort(alist): """希尓排序""" # n = 9 n = len(alist) # gap = 4 gap = n // 2 # i = gap # for i in range(gap, n): # i = [gap, gap+1, 阅读全文
摘要:
# coding:utf-8 def insert_sort(alist): """插入排序""" n = len(alist) for j in range(1, n): # j = [1, 2, 3, n-1] # i 代表內層循環起始值 i = j # 執行從右邊的無序序列中取出第一個元素,即 阅读全文
摘要:
# alist = [17, 20, 93,54,77,31,44,55,226]# 0 1 2 3 4 5 6 7 8##j=0#min = 0 0+1#alist[0], alist[3] = alist[3], alist[0]##j=1#min = 1 1+1#alist[1], alist 阅读全文
摘要:
# coding:utf-8 def bubble_sort(alist): """冒泡排序""" n = len(alist) for j in range(n-1): #count = 0 for i in range(0, n-1-j): #班長從頭走到尾 if alist[i] > alis 阅读全文
摘要:
# coding:utf-8 class Node(object): """結點""" def __init__(self, item): self.elem = item self.next = None self.prev = None class DoubleLinkList(object): 阅读全文
摘要:
# coding:utf-8 class Node(object): """結點""" def __init__(self, item): self.elem = item self.next = None self.pre = None class DoubuleLinkList(object): 阅读全文