def findMinIndex(A, start):
min_index = start
start += 1
while start < len(A):
if A[start] < A[min_index]:
min_index = start
start += 1
return min_index
def selectionSort(A):
i = 0
while i < len(A):
min_index = findMinIndex(A, i)
if i != min_index:
A[i], A[min_index] = A[min_index], A[i]
i += 1
A = [5, 2, 6, 7, 2, 1, 0, 3]
selectionSort(A)
for num in A:
print(num, end=' ')
Source: Interviewbit.com
Comments