Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ==========================
- # Ф-я поиска наименьшнго эл-та
- # ==========================
- def findSmallest(arr):
- smallest = arr[0] #для хранения наименьшего значения
- smallestIndex = 0 #Для хранения индекса наименьшего значения
- for i in range (1, len(arr)):
- if arr[i] < smallest:
- smallest = arr[i]
- smallestIndex = i
- return smallestIndex
- # ================
- # Сортировка выбором
- # ================
- def selectionSort(arr): #Сортирует массив
- newArr = []
- for i in range (len(arr)):
- smallest = findSmallest(arr) #находит наименьший элемент в массиве
- newArr.append(arr.pop(smallest))#и добавляет его в новый массив
- return newArr
- # Пример
- print(selectionSort([5, 3, 6, 2, 10]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement