摘要: 链表反转 #!/usr/bin/env python # -*- coding: utf-8 -*- # @File : ReverseSingleLinkImpl.py class Node: data = 0 next = None def build_single_link_list(node 阅读全文
posted @ 2021-08-31 15:25 holmes_now 阅读(27) 评论(0) 推荐(0)
摘要: 栈的Python实现 栈可以用顺序表方式实现,也可以用链表方式实现。我大Python的内建数据结构太强大,可以用list直接实现栈,简单快捷。人生苦短,我用Python。代码如下: class Stack(object): # 初始化栈为空列表 def __init__(self): self.it 阅读全文
posted @ 2021-08-31 14:40 holmes_now 阅读(36) 评论(0) 推荐(0)
摘要: # 针对有序查找表的二分查找算法 # 时间复杂度O(log(n)) def binary_search(lis, key): low = 0 high = len(lis) - 1 time = 0 while low < high: time += 1 mid = int((low + high) 阅读全文
posted @ 2021-08-31 14:30 holmes_now 阅读(55) 评论(0) 推荐(0)