随笔分类 -  数据结构

摘要:#coding:utf-8 ''' 折半查找返回值是mid+1 ''' def half_search(data,target): low,high = 0,len(data)-1 while low target: high = mid -1 else: low = mid+1 return 0 d... 阅读全文
posted @ 2016-03-17 15:04 gopher-lin 阅读(151) 评论(0) 推荐(0)
摘要:def fab(n): if n==1: return 1 if n==0: return 0 else: result=int(fab(n-1))+int(fab(n-2)) return resul 阅读全文
posted @ 2016-03-17 09:54 gopher-lin 阅读(160) 评论(0) 推荐(0)
摘要:#coding:utf-8 def demo(data,temp): for i in range(len(data)-1): if data[i] == temp : print i break else: print u'没有满足条件的数字' if __name__ == "__... 阅读全文
posted @ 2016-03-16 17:11 gopher-lin 阅读(92) 评论(0) 推荐(0)
摘要:array = [1,2,3,6,5,4] for i in range(len(array)): for j in range(i): if array[j] > array[j + 1]: array[j], array[j + 1] = array[j + 1], array[j] print array print ... 阅读全文
posted @ 2016-03-16 16:44 gopher-lin 阅读(92) 评论(0) 推荐(0)
摘要:def demo(data): for i in range(len(data)-1,0,-1): positon_max = 0 for k in range(i): if data[positon_max] > data[k]: positon_max = k data[i],data[positon... 阅读全文
posted @ 2016-03-16 16:43 gopher-lin 阅读(136) 评论(0) 推荐(0)
摘要:coding:utf 8 ''' 堆排序的实现 ''' import heapq def HeapSort(list): heapq.heapify(list) heap = [] while list: heap.append(heapq.heappop(list)) list[:] ... 阅读全文
posted @ 2016-01-12 10:20 gopher-lin 阅读(130) 评论(0) 推荐(0)