让算法变得简单一点
Project description
salgorithm
介绍:
此库是一个算法简化工具可以让算法只用一行代码就吧复杂的算法写成一个简单的只用函数就能调用的算法
简化的算法:
- 冒泡排序(Bubble Sort)
- 选择排序(Selection Sort)
- 插入排序(Insertion Sort)
- 归并排序(Merge Sort)
- 快速排序(Quick Sort)
- 堆排序(Heap Sort)
- 二分查找(Binary Search)
- 深度优先搜索(Depth First Search,DFS)
调用库:
from salgorithm import *
算法调用:
# 冒泡排序(Bubble Sort)
arr = [5, 3, 8, 2, 1, 9, 4, 7, 6, 10]
sorted_arr = bubble_sort(arr)
print(f"冒泡排序结果:{sorted_arr}")
# 选择排序(Selection Sort)
arr = [5, 3, 8, 2, 1, 9, 4, 7, 6, 10]
sorted_arr = selection_sort(arr)
print(f"选择排序结果:{sorted_arr}")
# 插入排序(Insertion Sort)
arr = [5, 3, 8, 2, 1, 9, 4, 7, 6, 10]
sorted_arr = insertion_sort(arr)
print(f"插入排序结果:{sorted_arr}")
# 归并排序(Merge Sort)
arr = [5, 3, 8, 2, 1, 9, 4, 7, 6, 10]
sorted_arr = merge(arr)
print(f"归并排序结果:{sorted_arr}")
# 快速排序(Quick Sort)
arr = [5, 3, 8, 2, 1, 9, 4, 7, 6, 10]
sorted_arr = quick_sort(arr)
print(f"快速排序结果:{sorted_arr}")
# 堆排序(Heap Sort)
arr = [5, 3, 8, 2, 1, 9, 4, 7, 6, 10]
heapify(arr)
print(f"堆排序结果:{arr}")
# 二分查找(Binary Search)
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
target = 5
result = binary_search(arr, target)
print(f"二分搜索结果:{result}")
# 深度优先搜索(Depth First Search,DFS)
# 此算法简易暂时别用因为还没完全写好
graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [],
'E': ['F'],
'F': []
}
start_node = 'A'
dfs(graph, start_node)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
salgorithm-0.0.8.tar.gz
(7.5 kB
view details)
File details
Details for the file salgorithm-0.0.8.tar.gz
.
File metadata
- Download URL: salgorithm-0.0.8.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41d17a86c526ea5e46e8c7c6bc3a0e52b4b92913bf1c8e75efee1f4fd0117be1 |
|
MD5 | 7c2b671f4beffb1c88194fd3b7e2b53b |
|
BLAKE2b-256 | d7c319049320ccc522f91d174b30d5bcda516d627d0ce7c6d29fc2254e9b71c3 |