链表是由一系列节点组成的元素集合。每个节点包含两部分,数据域 item 和指向下一个节点的指针 next。通过节点之间的相互连接,最终串联成一个链表。
class Node: def __init__(self, item): self.item = item self.next = None
class Node: def __init__(self, item): self.item = item ...
2020年11月11日 20:06 作者:nancy 分类:[算法与数据结构] 1756
给一个二维列表,表示迷宫(0 表示通道,1 表示围墙)。给出算法,求一条走出迷宫的路径。
maze = [ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 1, 0, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 0, 0, 1, 0, 1], [1, 0, 0, 0, 0, 1, 1, 0, 0, 1], [1, 0, 1, 1, 1, 0, 0, 0, 0, 1], [1,...
2020年11月9日 23:29 作者:nancy 分类:[算法与数据结构] 1743
rear == Maxsize + 1
时,再前进一个位置就自动到 0front = (front + 1) % Maxsize
rear ...
2020年11月9日 20:37 作者:nancy 分类:[算法与数据结构] 1580
li.append()
li.pop()
li[-1]
class Stack: def __init__(self): self.stack = [] def pu...
2020年11月8日 21:25 作者:nancy 分类:[算法与数据结构] 1551
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性:
2020年11月7日 16:28 作者:nancy 分类:[LeetCode] 1533
基数排序是一种非比较型整数排序算法,其原理是将整数按位数切割成不同的数字,然后按每个位数分别比较。由于整数也可以表达字符串(比如名字或日期)和特定格式的浮点数,所以基数排序也不是只能使用于整数。
def radix_sort(lst): max_num = max(lst) it = 0 # 最大值 9->1, 99->2, 888->3, 10000->5 whil...
2020年11月7日 15:15 作者:nancy 分类:[算法与数据结构] 1587
def bucket_sort(lst, n=100, max_num=10000): buckets = [[] for _ in range(n)] # 创建桶 for val in lst: i = min(v...
2020年11月7日 13:24 作者:nancy 分类:[算法与数据结构] 1783
def count_sort(lst, max_count=100): count = [0 for _ in range(max_count+1)] # 生成一个包含 max_count 个零的列表 for val in lst: count[val] += 1 lst.clear() # 清空原列表 for ind, val in e...
2020年11月6日 22:50 作者:nancy 分类:[算法与数据结构] 1502
d₁ = n // 2
,将元素分为 d₁ 个组,每组相邻元素之间距离为 d₁,在各组内进行直接插入排序;d₂ = d₁ // 2
,重复上述分组排序过程,直到 dᵢ = 1
,即所有元素在同一组内进行直接插入排序。# 希尔排序 def insert_sort_gap(lst, gap): for ...
2020年11月6日 22:15 作者:nancy 分类:[算法与数据结构] 1610
def merge(lst, low, mid, high): i = low j = mid + 1 temp = [] while i <= mid and j <...
2020年11月6日 18:16 作者:nancy 分类:[算法与数据结构] 1652
你还没有登录,请 或者