数据结构与算法
sky0Lan
打杂的
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python 用循环链表存储实现循环队列类
# encoding=UTF-8""" 用循环链表存储实现循环队列类"""class CircularQueue: """Queue implementation using circularly linked list for storage.""" class _Node: """lightweight, nonpublick class for storing a singly linked node.""" __slots__ =原创 2021-07-02 14:47:25 · 398 阅读 · 0 评论 -
python 单项链表实现栈
# encoding=UTF-8""" 单项链表实现栈"""class LinkedStack: """LIFO Stack implementation using a singly linked list for storage.""" # nested _Node class class _Node: """lightweight, nonpublick class for storing a singly linked node."""原创 2021-06-25 19:50:16 · 230 阅读 · 0 评论 -
递归, 绘制英式标尺 -- 数据结构与算法
长度为3 的 1英寸标尺,即需要标注出 0, 1/4, 1/2, 3/4, 1 这些尺寸def draw_line(tick_length, tick_label=''): line = '-' * tick_length if tick_label: line += ' ' + tick_label print(line)def draw_interval(center_length): if center_length > 0:原创 2021-05-29 16:55:06 · 410 阅读 · 0 评论 -
广度优先与深度优先
# coding:utf-8def bfs(graph, start, end): path = [] visited = [start] while visited: current = visited.pop(0) if current not in path: path.append(current) if current == end: # print(pat原创 2021-04-21 10:49:57 · 172 阅读 · 1 评论 -
统计指定目录空间大小
# encoding=UTF-8import os""" 递归计算目录空间大小"""def disk_usage(path): total = os.path.getsize(path) if os.path.isdir(path): for filename in os.listdir(path): childpath = os.path.join(path, filename) total += disk原创 2021-06-09 15:21:49 · 173 阅读 · 0 评论 -
反转列表数据
# encoding=UTF-8""" 反转列表"""def reverse(S, start, stop): # 使用递归实现 if start < stop - 1: S[start], S[stop-1] = S[stop-1], S[start] reverse(S, start+1, stop-1)def reverse_iterative(S): # 使用循环实现 start, stop = 0, le原创 2021-06-09 15:23:08 · 187 阅读 · 0 评论 -
二分法查找
# encoding=UTF-8""" 二分查找"""def binary_search(data, target, low, high): # 使用递归实现 if low > high: return False else: mid = (low + high) // 2 if target == data[mid]: return True elif target &l原创 2021-06-09 15:20:33 · 131 阅读 · 0 评论 -
数据结构与算法 python
数据结构与算法 python语言实现 各章节代码下载原创 2021-04-22 14:48:37 · 128 阅读 · 0 评论 -
python 一个简单模拟 list 的动态列表
# encoding=UTF-8import ctypesclass DynamicArray: """a dynamic array class akin to a simplified python list""" def __init__(self): """create an empty array""" self._n = 0 # count actual eleme原创 2021-06-16 20:13:16 · 445 阅读 · 0 评论 -
python 插入排序算法
# encoding=UTF-8""" 插入排序算法 input: an array A of n comparable elements output: the array A with elements rearranged in nondecreasing order for k from 1 to n - 1 do insert A[k] at its proper location within A[0]...A[k]"""def in原创 2021-06-17 18:51:58 · 139 阅读 · 0 评论 -
python 数据结构 栈 使用
# encoding=UTF-8""" 用 python 列表作为存储实现一个栈 采用适配器模式,在内部维护一个数组,对栈不需要的方法进行隐藏"""class ArrayStack: """LIFO stack implementation using a python list as underlying storage""" def __init__(self): """create an empty stack""" sel原创 2021-06-21 19:00:24 · 201 阅读 · 0 评论
分享