This may seem like a simple question but when I attempted to implement selection sort in Python, I do not get a sorted list. Is there something wrong with my implementation?
def selectionSort (B, annotate=True):
for i in range(len(A)):
for j in range(1,len(A)):
if(A[i] > A [j]):
A[i], A[j] = A[j], A[i]
A = [5, 4, 3, 2, 1]
A_sorted = selectionSort (A)
print ("Sorted " + str(A) + " = " + str(A_sorted))
A = [10, 7, 8, 40, 2, 5]
A_sorted = selectionSort (A)
print ("Sorted " + str(A) + " = " + str(A_sorted))
Here's what I get:
>>> (executing lines 1 to 74 of "selection_sort_103_v2.py")
Sorted [1, 5, 4, 3, 2] = None
Sorted [2, 40, 10, 8, 7, 5] = None
A