博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
选择排序
阅读量:4171 次
发布时间:2019-05-26

本文共 1164 字,大约阅读时间需要 3 分钟。

python实现:

def selection_sort(collection):    length = len(collection)    for i in range(length-1):        least = i;        for k in range(i+1,length):            if collection[k] < collection[least]:                least = k        if least != i:            collection[least],collection[i] = (collection[i],collection[least])    return collectionif __name__ == "__main__":    user_input = input("输入排序数字,按逗号分隔:\n").strip()    unsorted = [int(item) for item in user_input.split(",")]    print(selection_sort(unsorted))

java实现:

public class select_sort {
public static void main(String[] args) throws IOException {
System.out.println("输入排序数字,按逗号分隔:"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] arra = br.readLine().split(","); Integer[] array = new Integer[arra.length]; for(int i=0; i
notSort[j]) least = j; } if(least != i){
int temp = 0; temp = notSort[least]; notSort[least] = notSort[i]; notSort[i] = temp; } } return notSort; } }

转载地址:http://lukai.baihongyu.com/

你可能感兴趣的文章
在C++中如何实现模板函数的外部调用
查看>>
HTML5学习之——HTML 5 拖放
查看>>
HTML5学习之——HTML 5 Canvas vs. SVG
查看>>
HTML5学习之——HTML 5 应用程序缓存
查看>>
HTML5学习之——HTML 5 Web Workers
查看>>
HTML5学习之——HTML 5 Canvas
查看>>
HTML5学习之——HTML5 内联 SVG
查看>>
HTML5学习之——HTML 5 服务器发送事件
查看>>
SVG学习之——HTML 页面中的 SVG
查看>>
SVG 形状学习之——SVG圆形
查看>>
SVG 滤镜学习之——SVG 滤镜
查看>>
mysql中用命令行复制表结构的方法
查看>>
hbase shell出现ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException
查看>>
让代码变得更优雅-Lombok
查看>>
解决Rhythmbox乱码
查看>>
豆瓣爱问共享资料插件发布啦
查看>>
Ubuntu10.10 CAJView安装 读取nh\kdh\caj文件 成功
查看>>
kermit的安装和配置
查看>>
vim 配置
查看>>
openocd zylin
查看>>