📄 ssort.m
字号:
function out=ssort(a)
%ssort selection sort data in ascending order
%function ssort sorts a numeric data set into ascending order.
% Note that the selection sort is relatively inefficient. Don not
% use this function for large data sets. user matlab's "sort" function
% instead.
%define variables:
% a ----input array to sort
% ii ---index variable
% iptr ---pointer to min value
% jj ---index variable
% nvals --number of values in "a"
% out ---sorted output array
% temp ----Temp variable for swapping
% Record of revisionss:
% Date programmer Description of change
% ========== ============ ======================
% 12/19/98 S.J.Chapman Original code
% Get the length of the array to sort
nvals=size(a,2);
% Sort the input array
for ii=1:nvals-1
% Find the minimum value in a(ii) through a(n)
iptr=ii;
for jj=ii+1:nvals
if a(jj)<a(iptr)
iptr=jj;
end
end
%iptr now points to the minimum value,so swap a(iptr)
% with a(ii) if ii~=iptr
if ii~=iptr
temp=a(ii);
a(ii)=a(iptr);
a(iptr)=temp;
end
end
% Pass data back to caller
out=a;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -