Some algorithms cases

The numbers in ascending order, (step operation and with pycharm breakpoints Debugger view program) 
DEF
find_smallest (ARR): Smallest = ARR [0] smallest_index = 0 for I in Range (. 1 , len (ARR)) : IF ARR [I] < Smallest: Smallest = ARR [I] smallest_index = I return smallest_index DEF selection_sort (ARR): new_arr = [] for I in Range (len (ARR)): Smallest = find_smallest (ARR) new_arr.append(arr.pop(smallest)) return new_arr print(selection_sort([8,6,4,9,2]))

 

Guess you like

Origin www.cnblogs.com/bchy/p/11707451.html