python简单算法

冒泡

python 复制代码
def boll(lis):
    i = 0
    while i<len(lis)-1:
        j = 0
        while j<len(lis)-1-i:
            if lis[j] > lis[j+1]:
                lis[j],lis[j + 1] = lis[j+1],lis[j]
            j+=1
        i+=1

选择排序

python 复制代码
def selct1(lit):
    i = 0
    while i<len(lit)-1:
        j =i+1
        min1 = i
        while j < len(lit):
            if lit[j] < lit[min1]:
                min1 = j
            j += 1
        lit[i],lit[min1] = lit[min1],lit[i]

        i+=1

插入

python 复制代码
def insert(lit):
    i = 1
    for i in range(1,len(lit)):
        j = i-1#手牌下标
        tmp = lit[i] #抓牌下标
        while j>=0 and lit[j]>tmp:
            lit[j+1] = lit[j]
            j-=1
        lit[j+1] = tmp
相关推荐
程序员Sunday9 小时前
Promise.all、allSettled、race、any 怎么选,失败后其他请求会怎样
开发语言·前端·javascript
小静AI工程实验室10 小时前
Python 爬虫解析 JSON-LD:多块 script、@graph 与坏数据的 9 个边界
爬虫·python·json
hetao173383710 小时前
2026-10-07 hetao1733837 的刷题记录
c++·算法
daxiangxm10 小时前
GEO策略:让AI直接引用你的内容
开发语言·团队开发·运维开发·个人开发·数据库开发
jason.zeng@150220710 小时前
(八)现有架构上新增一个通用Excel导出工具
python·架构·langchain·excel·llama
袁袁袁袁满10 小时前
AI Agent 如何“看懂“互联网?
爬虫·python·自动化·爬虫实战·多线程爬虫
泡海椒10 小时前
JQuick-Excel 实战:用 VALIDATION 建立可维护的 Excel 导入校验
开发语言·python·excel
Nil20810 小时前
leetcode 279完全平方数
算法·leetcode·职场和发展
longlongzihan10 小时前
前缀积与后缀积 —— LeetCode 238. 除了自身以外数组的乘积
开发语言·c++·leetcode
Duang007_10 小时前
生产可观测性:从“系统慢“到“根因“的完整链路(Go / TypeScript)
后端·python·golang·typescript·prometheus