3 c ###################################################
4 c ## COPYRIGHT (C) 1990 by Jay William Ponder ##
5 c ## All Rights Reserved ##
6 c ###################################################
8 c #########################################################
10 c ## subroutine sort -- heapsort of an integer array ##
12 c #########################################################
15 c "sort" takes an input list of integers and sorts it
16 c into ascending order using the Heapsort algorithm
19 subroutine sort (n,list)
26 c perform the heapsort of the input list
38 if (index .le. 1) then
45 dowhile (j .le. index)
46 if (j .lt. index) then
47 if (list(j) .lt. list(j+1)) j = j + 1
49 if (lists .lt. list(j)) then
63 c ##############################################################
65 c ## subroutine sort2 -- heapsort of real array with keys ##
67 c ##############################################################
70 c "sort2" takes an input list of reals and sorts it
71 c into ascending order using the Heapsort algorithm;
72 c it also returns a key into the original ordering
75 subroutine sort2 (n,list,key)
84 c initialize index into the original ordering
90 c perform the heapsort of the input list
102 list(index) = list(1)
105 if (index .le. 1) then
113 dowhile (j .le. index)
114 if (j .lt. index) then
115 if (list(j) .lt. list(j+1)) j = j + 1
117 if (lists .lt. list(j)) then
133 c #################################################################
135 c ## subroutine sort3 -- heapsort of integer array with keys ##
137 c #################################################################
140 c "sort3" takes an input list of integers and sorts it
141 c into ascending order using the Heapsort algorithm;
142 c it also returns a key into the original ordering
145 subroutine sort3 (n,list,key)
155 c initialize index into the original ordering
161 c perform the heapsort of the input list
173 list(index) = list(1)
176 if (index .le. 1) then
184 dowhile (j .le. index)
185 if (j .lt. index) then
186 if (list(j) .lt. list(j+1)) j = j + 1
188 if (lists .lt. list(j)) then
204 c #################################################################
206 c ## subroutine sort4 -- heapsort of integer absolute values ##
208 c #################################################################
211 c "sort4" takes an input list of integers and sorts it into
212 c ascending absolute value using the Heapsort algorithm
215 subroutine sort4 (n,list)
223 c perform the heapsort of the input list
233 list(index) = list(1)
235 if (index .le. 1) then
242 dowhile (j .le. index)
243 if (j .lt. index) then
244 if (abs(list(j)) .lt. abs(list(j+1))) j = j + 1
246 if (abs(lists) .lt. abs(list(j))) then
260 c ################################################################
262 c ## subroutine sort5 -- heapsort of integer array modulo m ##
264 c ################################################################
267 c "sort5" takes an input list of integers and sorts it
268 c into ascending order based on each value modulo "m"
271 subroutine sort5 (n,list,m)
280 c perform the heapsort of the input list
290 list(index) = list(1)
292 if (index .le. 1) then
299 dowhile (j .le. index)
300 if (j .lt. index) then
301 jmod = mod(list(j),m)
302 j1mod = mod(list(j+1),m)
303 if (jmod .lt. j1mod) then
305 else if (jmod.eq.j1mod .and. list(j).lt.list(j+1)) then
310 jmod = mod(list(j),m)
311 if (smod .lt. jmod) then
315 else if (smod.eq.jmod .and. lists.lt.list(j)) then
329 c #############################################################
331 c ## subroutine sort6 -- heapsort of a text string array ##
333 c #############################################################
336 c "sort6" takes an input list of character strings and sorts
337 c it into alphabetical order using the Heapsort algorithm
340 subroutine sort6 (n,list)
345 character*(*) list(*)
348 c perform the heapsort of the input list
358 list(index) = list(1)
360 if (index .le. 1) then
367 dowhile (j .le. index)
368 if (j .lt. index) then
369 if (list(j) .lt. list(j+1)) j = j + 1
371 if (lists .lt. list(j)) then
385 c ################################################################
387 c ## subroutine sort7 -- heapsort of text strings with keys ##
389 c ################################################################
392 c "sort7" takes an input list of character strings and sorts it
393 c into alphabetical order using the Heapsort algorithm; it also
394 c returns a key into the original ordering
397 subroutine sort7 (n,list,key)
404 character*(*) list(*)
407 c initialize index into the original ordering
413 c perform the heapsort of the input list
425 list(index) = list(1)
428 if (index .le. 1) then
436 dowhile (j .le. index)
437 if (j .lt. index) then
438 if (list(j) .lt. list(j+1)) j = j + 1
440 if (lists .lt. list(j)) then
456 c #########################################################
458 c ## subroutine sort8 -- heapsort to unique integers ##
460 c #########################################################
463 c "sort8" takes an input list of integers and sorts it into
464 c ascending order using the Heapsort algorithm, duplicate
465 c values are removed from the final sorted list
468 subroutine sort8 (n,list)
476 c perform the heapsort of the input list
486 list(index) = list(1)
488 if (index .le. 1) then
491 c remove duplicate values from final list
495 if (list(i-1) .ne. list(i)) then
506 dowhile (j .le. index)
507 if (j .lt. index) then
508 if (list(j) .lt. list(j+1)) j = j + 1
510 if (lists .lt. list(j)) then
524 c #############################################################
526 c ## subroutine sort9 -- heapsort to unique text strings ##
528 c #############################################################
531 c "sort9" takes an input list of character strings and sorts
532 c it into alphabetical order using the Heapsort algorithm,
533 c duplicate values are removed from the final sorted list
536 subroutine sort9 (n,list)
541 character*(*) list(*)
544 c perform the heapsort of the input list
554 list(index) = list(1)
556 if (index .le. 1) then
559 c remove duplicate values from final list
563 if (list(i-1) .ne. list(i)) then
574 dowhile (j .le. index)
575 if (j .lt. index) then
576 if (list(j) .lt. list(j+1)) j = j + 1
578 if (lists .lt. list(j)) then