当前位置:网站首页>【经典排序】快速排序
【经典排序】快速排序
2022-08-10 23:50:00 【冰冷的希望】
1.快速排序
选取第一个数为基准值,把比基准值大的放在左边,小的放在右边,依次遍历,最后有序
快速排序总是优于归并排序

2.代码实现
def quick_sort(my_list, start, end):
if start >= end:
return
mid = my_list[start]
low = start
height = end
while low < height:
while low < height and mid <= my_list[height]:
height -= 1
my_list[low] = my_list[height]
while low < height and mid > my_list[low]:
low += 1
my_list[height] = my_list[low]
my_list[low] = mid
quick_sort(my_list, start, low - 1)
quick_sort(my_list, low + 1, end)
if __name__ == '__main__':
pass
a = [5, 6, 1, 9, 0, 4, 6, 8]
print(a)
quick_sort(a, 0, len(a) - 1)
print(a)
3.复杂度
最优时间复杂度: O(nlogn)
最坏时间复杂度: O(n^2)
平均时间复杂度: O(nlogn)
稳定性:不稳定
边栏推荐
- 【C语言】初识指针
- Multilingual Translation - Multilingual Translation Software Free
- 8. WEB 开发-静态资源访问
- [Excel knowledge and skills] Convert "false" date to "true" date format
- 软件测试证书(1)—— 软件评测师
- "NIO Cup" 2022 Nioke Summer Multi-School Training Camp 2 DGHJKL Problem Solution
- 12. Handling JSON
- Ali P7 bask in January payroll: hard to fill the, really sweet...
- 镜头之滤光片---关于日夜两用双通滤光片
- 12. 处理 JSON
猜你喜欢

YOLOv5的Tricks | 【Trick13】YOLOv5的detect.py脚本的解析与简化

Where can I download IEEE papers?

回收站的文件删了怎么恢复,回收站文件恢复的两种方法

I caught a 10-year-old Ali test developer, and after talking about it, I made a lot of money...

sqlmap结合dnslog快速注入

Qt入门(六)——抽奖系统的实现

Lens filter---about day and night dual-pass filter
![[Excel knowledge and skills] Convert](/img/96/ece9c3885fd4abe4bf4d211813b9c4.png)
[Excel knowledge and skills] Convert "false" date to "true" date format

特殊类与类型转换

Web-based meal ordering system in epidemic quarantine area
随机推荐
2. Dependency management and automatic configuration
HGAME 2022 Week1 writeup
有哪些可以投稿软件工程/系统软件/程序设计语言类外文期刊、会议?
ROS实验笔记之——安装QPEP以及Intel-MKL
Three-column layout implementation
分布式.性能优化
[Excel知识技能] 将“假“日期转为“真“日期格式
Where can I download IEEE papers?
李彦宏拆墙交朋友,大厂“塑料友情”能否帮百度啃下硬骨头?
Which translation software is more accurate [Free]
图像识别和语义分割的区别
Qt入门(六)——抽奖系统的实现
“蔚来杯“2022牛客暑期多校训练营3 DF题解
SQL注入基础---order by \ limit \ 宽字节注入
How to recover data from accidentally deleted U disk, how to recover deleted data from U disk
Introduction to Qt (6) - Implementation of the lottery system
[C language] Detailed explanation of data storage
[C language] Implementation of guessing number game
CF1534F2-Falling Sand (Hard Version)
22年全国程序员1月薪资出炉,才知道年薪 40 万以上的有这么多?