Added selection-sort for MATLAB. (#26856)

This commit is contained in:
Mahmud031
2018-10-24 05:28:20 +03:00
committed by Martin Payne
parent 8b85713ca3
commit 5986d9fb66

View File

@ -77,6 +77,24 @@ def seletion_sort(arr):
arr[i], arr[min_i] = arr[min_i], arr[i]
```
### Implementation in MATLAB
```MATLAB
function [sorted] = selectionSort(unsorted)
len = length(unsorted);
for i = 1:1:len
minInd = i;
for j = i+1:1:len
if unsorted(j) < unsorted(minInd)
minInd = j;
end
end
unsorted([i minInd]) = unsorted([minInd i]);
end
sorted = unsorted;
end
```
### Properties
* Space Complexity: <b>O(n)</b>