python: Bubble Sort
ubuntu 升级至python 3.11
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.11
python3.11 --version
root@ubuntu:/home/pycharm/pycharm-2023.2.1/bin# sh pycharm.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | # encoding: utf-8 # 版权所有 2023 涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 311 # Datetime : 2023/9/21 21:55 # User : geovindu # Product : PyCharm # Project : EssentialAlgorithms # File : SortingAlgorithms.py # explain : 学习 import tkinter as tk from tkinter import ttk import itertools import math import sys import os class SortingAlgorithms( object ): """ 排序算法 """ def BubbleSort(array: list ): """ 1。Bubble Sort冒泡排序法 :return: """ # loop to access each array element for i in range ( len (array)): # loop to compare array elements for j in range ( 0 , len (array) - i - 1 ): # compare two adjacent elements # change > to < to sort in descending order if array[j] > array[j + 1 ]: # swapping elements if elements # are not in the intended order temp = array[j] array[j] = array[j + 1 ] array[j + 1 ] = temp def BubbleSort2(array: list ): """ 1。Bubble Sort冒泡排序法 :return: """ # loop through each element of array for i in range ( len (array)): # keep track of swapping swapped = False # loop to compare array elements for j in range ( 0 , len (array) - i - 1 ): # compare two adjacent elements # change > to < to sort in descending order if array[j] > array[j + 1 ]: # swapping occurs if elements # are not in the intended order temp = array[j] array[j] = array[j + 1 ] array[j + 1 ] = temp swapped = True # no swapping means the array is already sorted # so no need for further comparison if not swapped: break |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # encoding: utf-8 # 版权所有 2023 涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 311 # Datetime : 2023/9/21 22:00 # User : geovindu # Product : PyCharm # Project : EssentialAlgorithms # File : SortingExample.py # explain : 学习 import ChapterOne.SortingAlgorithms class Example( object ): """" 实例 """ def Bubble( self ): data = [ - 2 , 45 , 0 , 11 , - 9 ] ChapterOne.SortingAlgorithms.SortingAlgorithms.BubbleSort(data) print ( '冒泡排序法 Sorted Array in Ascending Order:' ) print (data) |
调用:
1 2 | exm = BLL.SortingExample.Example() exm.Bubble() |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2022-09-21 CSharp: Bridge Pattern
2022-09-21 Java: Immutable Pattern
2016-09-21 csharp: Oracle Stored Procedure DAL using ODP.NET
2014-09-21 Create a soft keyboard
2012-09-21 SQL 生成公曆和農曆對照數據續--创建萬年曆查找各種周期性節日數據
2010-09-21 Csharp,Javascript 获取显示器的大小的几种方式
2009-09-21 谷歌地图API学习