算法与数据结构
算法与数据结构
qiguangxu_ts
这个作者很懒,什么都没留下…
展开
-
并查集 (Union Find)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : guangxu.qi # @Time : 2020/11/6 15:40 # @FileName: UnionFind.py # @Description: class UnionFind(object): def __init__(self, n): # 根节点个数 self.root_num = n self.parent原创 2020-11-06 16:08:44 · 657 阅读 · 1 评论 -
堆排序(Heap Sort)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : guangxu.qi # @Time : 2020/10/23 15:01 # @FileName: heap_sort.py # @Description: def heap_sort(alist): length = len(alist) # 倒序对每个非叶子节点进行堆排序 for i in range(length // 2 - 1, -1, -1):原创 2020-10-23 15:10:21 · 112 阅读 · 0 评论 -
选择排序(Selection Sort)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : guangxu.qi # @Time : 2020/10/23 10:28 # @FileName: selection_sort.py # @Description: def selection_sort(alist): for i in range(len(alist) - 1): index = 0 for j in range(1,原创 2020-10-23 10:29:51 · 80 阅读 · 0 评论 -
栈的应用之括号匹配
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : guangxu.qi # @Time : 2020/9/28 15:48 # @FileName: per_checker.py # @Description: 判断括号是否匹配 { { ( [ ] [ ] ) } ( ) } from algorithms.datastruct.Stack import Stack def par_checker(symbol_string)原创 2020-09-28 16:03:34 · 74 阅读 · 0 评论 -
栈
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : guangxu.qi # @Time : 2020/9/28 15:42 # @FileName: Stack.py # @Description: class Stack(): def __init__(self): self.items = [] def is_empty(self): return self.items ==原创 2020-09-28 15:44:29 · 52 阅读 · 0 评论 -
快速排序(Quick Sort)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : guangxu.qi # @Time : 2020/9/15 17:07 # @FileName: 07_quick_sort.py # @Description: def quick_sort(alist): quick_sort_helper(alist, 0, len(alist) - 1) def quick_sort_helper(alist, first,原创 2020-09-15 17:22:40 · 108 阅读 · 0 评论 -
归并排序(Merge Sort)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : guangxu.qi # @Time : 2020/9/15 15:37 # @FileName: 07_merge_sort.py # @Description: def merge_sort(alist): if len(alist) <= 1: return alist mid = len(alist) // 2 left =原创 2020-09-15 16:57:02 · 75 阅读 · 0 评论 -
谢尔排序(Shell Sort)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : guangxu.qi # @Time : 2020/9/15 15:06 # @FileName: 07_shell_sort.py # @Description: def shell_sort(alist): sublist_count = len(alist) // 2 while sublist_count > 0: for star原创 2020-09-15 15:22:23 · 137 阅读 · 0 评论 -
插入排序 (Insertion Sort)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : guangxu.qi # @Time : 2020/9/15 14:43 # @FileName: 07_insertion_sort.py # @Description: def insertion_sort(alist): for i in range(1, len(alist)): current_value = alist[i] po原创 2020-09-15 14:51:21 · 72 阅读 · 0 评论 -
冒泡排序(Bubble Sort)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : guangxu.qi # @Time : 2020/9/15 14:27 # @FileName: bubble_sort.py # @Description: def bubble_sort(alist): for i in range(len(alist) - 1): for j in range(len(alist) - 1 - i):原创 2020-09-15 14:34:52 · 115 阅读 · 0 评论