function out = c_sort1(a)
%C_SORT1 Selection sort character in ascending order
% Function C_SORT1 sorts a set of strings into 
% ascending (alphabetical) order.  The strings must
% be contained in a cell array.  This function uses 
% function c_strcmp from Chapter 6 to perform the 
% comparions.
%
% Usage:
%   out = c_sort1(a);
%
% where a is a cell array of strings, with one string
% per cell.
 
% Define variables:
%   a        -- Input cell array containing strings to sort
%   ii       -- Index variable
%   iptr     -- Pointer to min value
%   jj       -- Index variable
%   nvals    -- Number of cells in "a" 
%   out      -- Sorted output array
%   temp     -- Temp variable for swapping

%  Record of revisions:
%      Date       Programmer          Description of change
%      ====       ==========          =====================
%    03/25/00    S. J. Chapman        Original code

% Get the number of strings to sort
nvals = length(a);

% Sort the input array
for ii = 1:nvals-1
 
   % Find the minimum value in a(ii) through a(nvals)
   iptr = ii;
   for jj = ii+1:nvals
      if c_strcmp(a{jj},a{iptr}) < 0
         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;
