- 博客(3)
- 收藏
- 关注
原创 嵌套列表实现二叉树
1. 实现二叉树def BinaryTree(r): return [r,[],[]] def InsertLeft(root,newBranch): t=root.pop(1) if len(t)>1: #左子节点的列表不为空 root.insert(1,[newBranch,t,[]]) else: roo...
2020-04-15 17:24:55
850
原创 选择排序算法(python实现)
选择排序算法:基本思想:每轮初始值往后走一格,找到初始值后面的最小值,将找到的最小值与初始值做位置交换:示意图:代码:lst1=[5,8,6,3,6] #待排序列表for i in range(len(lst1)): #更换轮次 m=i #初始化最小值下标 for j in range(i+1,len(lst1)): #找最小值下标 if ls...
2020-04-15 17:05:19
488
原创 二叉堆-插入
最大堆-插入操作基本思想:新值先加入末尾,再上浮找到自己的位置示意图:代码实现:class MaxHeap: def __init__(self,heap): self.heap=heap def insert(self,num): self.heap.append(num) self.sh...
2020-04-15 16:52:36
501
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人