标签:find sorted pop while arc sele ESS 汇总 dex
def binary_search(arr, item):
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
guess = arr[mid]
if item == guess:
return mid
if item < guess:
high = mid - 1
else:
low = mid + 1
return None
def find_smallest(arr):
smaller = arr[0]
smaller_index = 0
for i in range(1, len(arr)):
if arr[i] < smaller:
smaller = arr[i]
smaller_index = i
return smaller_index
def selection_sort(arr):
sorted_arr = []
while arr:
smaller_index = find_smallest(arr)
sorted_arr.append(arr.pop(smaller_index))
return sorted_arr
标签:find sorted pop while arc sele ESS 汇总 dex
原文地址:https://www.cnblogs.com/jeffrey-yang/p/9738875.html