本文共 1164 字,大约阅读时间需要 3 分钟。
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))
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; inotSort[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/