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
相关推荐
小徐不徐说1 小时前
序列化与反序列化:把 C++ 对象可靠地保存下来
开发语言·数据库·c++·php
ZhengEnCi2 小时前
模型训练完整流程:从数据准备到模型上线的 10 个关键步骤(全文可跑)
后端·算法
ragnwang2 小时前
Notes: Python pybind11 import C++ module
开发语言·c++·python
王中阳Go2 小时前
后端转 Agent 岗面试怎么答:8 个高频问题与应答口径
人工智能·后端·python·大语言模型
Wang's Blog2 小时前
Java 项目实战: 交友项目 - 搜索附近的功能概述和分析
java·开发语言·交友
骑着蜗牛撵大象3272 小时前
大模型 Agent 的沙箱护栏:gVisor 隔离、出口白名单与审计闭环
java·开发语言·jvm·安全·agent沙箱·gvisor·microvm
weixin_307779133 小时前
RAG 面试陷阱——混合检索并非无条件优越:一个条件反转实验
人工智能·python·面试·职场和发展
Dxy12393102163 小时前
JS DES 加密详解
开发语言·javascript·arcgis
充值内卷3 小时前
我给桌面加了个鱼缸:C++ 写后端,WebView2 里养一座 Three.js 小岛
开发语言·javascript·c++
云和数据.ChenGuang3 小时前
深入解析 Python 的 dir():从用法到 CPython 源码实现
开发语言·人工智能·python·langchain