快速排序Python

焦飞
• 阅读 1576
def partition(arr, low, high):
    i = low - 1
    pivot = arr[high]
    for j in range(low, high):
        if arr[j] <= pivot:
            i = i+1
            arr[i],arr[j] = arr[j],arr[i]
    arr[i+1],arr[high] = arr[high],arr[i+1]# ???
    return i+1

def quick_sort(arr, low, high):
    if low < high:
        pi = partition(arr,low,high)
        quick_sort(arr, low, pi-1)
        quick_sort(arr, pi+1, high)
arr = [3,2,9,34,5,3,9,7,0,1]
quick_sort(arr, 0, len(arr)-1)
print(arr)
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
京东云开发者 京东云开发者
12个月前
Low-Code,一定“low”吗?
本文将重点介绍低代码相关知识,包括低代码的定义与意义、相关概念、行业发展等,同时介绍京东的低代码工具,期望能帮助大家更好地认识与理解低代码。
Stella981 Stella981
2年前
Python3:sqlalchemy对mysql数据库操作,非sql语句
Python3:sqlalchemy对mysql数据库操作,非sql语句python3authorlizmdatetime2018020110:00:00coding:utf8'''
Stella981 Stella981
2年前
Python学习之路(43)——自定义容器(container)
Python中常见的容器类型包括dict、tuple、list和string。其中,tuple和string是不可变容器,dict和list是可变容器。其区别在于,不可变容器一旦赋值后,其元素不能进行修改。然而,有时针对特殊需求,我们还需要自定义容易。1、自定义不可变容器类型:需要定义\_\_len\_\_和\_\_getitem\_\_方法;2
Wesley13 Wesley13
2年前
4cast
4castpackageloadcsv.KumarAwanish发布:2020122117:43:04.501348作者:KumarAwanish作者邮箱:awanish00@gmail.com首页:
Stella981 Stella981
2年前
Python之time模块的时间戳、时间字符串格式化与转换
Python处理时间和时间戳的内置模块就有time,和datetime两个,本文先说time模块。关于时间戳的几个概念时间戳,根据1970年1月1日00:00:00开始按秒计算的偏移量。时间元组(struct_time),包含9个元素。 time.struct_time(tm_y
沙摩柯 沙摩柯
3个月前
QCA9531: Low cost and high performance, wireless solution
TheQCA9531chip,despitebeingarelativelyearlychipmodel,isnotconsideredobsoleteforthisreason.Infact,itisstillwidelyusedinmanyrouter
helloworld_27355581 helloworld_27355581
1星期前
QCN9074, QCN6274 ,QCN6224- High performance - low power - for wide range of application
TheQCN9074,QCN6274andQCN6224arethreehighperformancewirelesscommunicationchipsthatemployadvancedmanufacturingprocessesandtechnolo
焦飞
焦飞
Lv1
男 · 暂时保密 · 算法工程师
文章
4
粉丝
0
获赞
0