Newer
Older
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
SUBROUTINE ISORTI_SLOAN(NL,LIST,NK,KEY)
************************************************************************
*
* PURPOSE:
* --------
*
* Order a list of integers in ascending sequence of their keys
* using insertion sort
*
* INPUT:
* ------
*
* NL - Length of LIST
* LIST - A list of integers
* NK - Length of KEY (NK must be ge NL)
* KEY - A list of integer keys
*
* OUTPUT:
* -------
*
* NL - Unchanged
* LIST - A list of integers sorted in ascending sequence of KEY
* NK - Unchanged
* KEY - Unchanged
*
* NOTE: Efficient for short lists only (NL lt 20)
* -----
*
* PROGRAMMER: Scott Sloan
* -----------
*
* LAST MODIFIED: 1 March 1991 Scott Sloan
* --------------
*
* COPYRIGHT 1989: Scott Sloan
* --------------- Department of Civil Engineering
* University of Newcastle
* NSW 2308
*
************************************************************************
INTEGER I,J,T
INTEGER NL,NK
INTEGER VALUE
INTEGER KEY(NK)
INTEGER LIST(NL)
*
DO 20 I=2,NL
T=LIST(I)
VALUE=KEY(T)
DO 10 J=I-1,1,-1
IF(VALUE.GE.KEY(LIST(J)))THEN
LIST(J+1)=T
GOTO 20
ENDIF
LIST(J+1)=LIST(J)
10 CONTINUE
LIST(1)=T
20 CONTINUE
END