Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions algorithms/sorting/select_sort.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%% Octave implementation for selection sort
function arrayToSort = select_sort(arrayToSort)
for i=1:length(arrayToSort)
%%smallest element in the unsorted list
minimun_index=i;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo? (minimum)

for j=i+1:length(arrayToSort)
if (arrayToSort(j) < arrayToSort(minimun_index))
minimun_index=j;
endif
endfor
%%replace the element with the minimun value of the unsorted array
arrayToSort([i minimun_index]) = arrayToSort([minimun_index i]);
endfor
endfunction