MCPcopy Create free account
hub / github.com/DasyDong/developer-roadmap / quick_sort

Function quick_sort

code/all_sort.py:3–10  ·  view source on GitHub ↗
(arr1)

Source from the content-addressed store, hash-verified

1# coding:utf-8
2# 快排
3def quick_sort(arr1):
4 if len(arr1) < 2:
5 return arr1
6 else:
7 pivot = arr1[0]
8 less = [i for i in arr1[1:] if i < pivot]
9 greater = [j for j in arr1[1:] if j >= pivot]
10 return quick_sort(less) + [pivot] + quick_sort(greater)
11
12# 归并
13def merge_sort(arr1):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected