Skip to content

Commit 48e12fa

Browse files
authored
Merge pull request #30 from AndresContreras96/select-sort-contribution
added select sort
2 parents 8f1dddb + 618abbf commit 48e12fa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

algorithms/sorting/select_sort.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
%% Octave implementation for selection sort
2+
function arrayToSort = select_sort(arrayToSort)
3+
for i=1:length(arrayToSort)
4+
%%smallest element in the unsorted list
5+
minimun_index=i;
6+
for j=i+1:length(arrayToSort)
7+
if (arrayToSort(j) < arrayToSort(minimun_index))
8+
minimun_index=j;
9+
endif
10+
endfor
11+
%%replace the element with the minimun value of the unsorted array
12+
arrayToSort([i minimun_index]) = arrayToSort([minimun_index i]);
13+
endfor
14+
endfunction

0 commit comments

Comments
 (0)