We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8f1dddb commit 618abbfCopy full SHA for 618abbf
algorithms/sorting/select_sort.m
@@ -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
14
+endfunction
0 commit comments