I have this python code here below (for bubble sort). Below that is my attempt at converting it to MATLAB code. I'm new to MATLAB, and I'm doing the conversion for practice. I would appreciate feedback on how accurate/incorrect my conversion is.
The python version:
def bubble_sort(alist):
return bubble_sort_helper(alist, len(alist))
def bubble_sort_helper(alist, n):
if n < 2:
return alist
for i in range(len(alist)-1):
if alist[i] > alist[i+1]:
temp = alist[i]
alist[i] = alist[i+1]
alist[i+1] = temp
return bubble_sort_helper(alist, n-1)
My attempt at a MATLAB conversion:
function a = bubble_sort(alist)
a = bubble_sort_helper(alist, size(alist))
end
function b = bubble_sort_helper(alist, n)
if n < 2
b = alist
end
for ii = size(alist)
if alist(1) > alist (ii+1)
temp = alist(ii)
alist(ii) = alist(ii+1)
alist(ii+1) = temp
end
end
b = bubble_sort_helper(alistn n-1)
end
alist[i], alist[i+1] = alist[i+1], alist[i]