-
Notifications
You must be signed in to change notification settings - Fork 1
/
i4col_sort_a.m
77 lines (67 loc) · 1.39 KB
/
i4col_sort_a.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function a = i4col_sort_a ( m, n, a )
%*****************************************************************************80
%
%% I4COL_SORT_A ascending sorts an I4COL.
%
% Discussion:
%
% In lexicographic order, the statement "X < Y", applied to two real
% vectors X and Y of length M, means that there is some index I, with
% 1 <= I <= M, with the property that
%
% X(J) = Y(J) for J < I,
% and
% X(I) < Y(I).
%
% In other words, the first time they differ, X is smaller.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Parameters:
%
% Input, integer M, the number of rows of A, and the length of
% a vector of data.
%
% Input, integer N, the number of columns of A.
%
% Input, integer A(M,N), the array of N columns of M-vectors.
%
% Output, integer A(M,N), the columns of A have been sorted in ascending
% lexicographic order.
%
if ( m <= 0 )
return
end
if ( n <= 1 )
return
end
%
% Initialize.
%
i = 0;
indx = 0;
isgn = 0;
j = 0;
%
% Call the external heap sorter.
%
while ( true )
[ indx, i, j ] = sort_heap_external ( n, indx, isgn );
%
% Interchange the I and J objects.
%
if ( 0 < indx )
a = i4col_swap ( m, n, a, i, j );
%
% Compare the I and J objects.
%
elseif ( indx < 0 )
isgn = i4col_compare ( m, n, a, i, j );
elseif ( indx == 0 )
break
end
end
return
end