Personal tools
You are here: Home teaching psych254 selsort.m
Log in


Forgot your password?
 

selsort.m

function [sorted]=selsort(original_array,sort_order) % SELSORT sorts 1D array using selection sort algorithm % implements selection sort algorithm % make sure the input is a 1-d array if ~exist('original_array'), fprintf('only 1-D numeric arrays are processed by selsort\n'); sorted=-1; return; elseif isempty(original_array) | ... ~isnumeric(original_array) | ... min(size(original_array)) > 1, fprintf('only 1-D numeric arrays are processed by selsort\n'); sorted=-1; return; end; % determine array length array_length=max(size(original_array)); input_array=original_array; % sort the array for x=1:array_length, min_loc=x; for y=x+1:array_length, if input_array(y)
Document Actions