I am implementing Stooge Sort in Python and I can't understand why my changes to the ordering of my array is not sticking. In other words, it appears that as I drill down recursively the cells are being swapped, but then after the function returns the ordering of my array is unchanged. Is it a scope issue, or some other pythonism I don't understand yet? Or is my algorithm incorrect?
import math
def StoogeSort(A):
n = len(A)
if (n == 2 and A[0] > A[1]):
tmp = A[0]
A[0] = A[1]
A[1] = tmp
elif n > 2:
m = int(math.ceil((2 * n) / 3))
StoogeSort(A[0:m])
StoogeSort(A[m-n:n])
StoogeSort(A[0:m])
return A
A = [4,2,1]
StoogeSort(A)
print "End:",A
A = [44,12,8,33,100]
StoogeSort(A)
print "End:",A