?? RIGHT := 110 ??
?? NEWTITLE := 'CREATE_SUBPRODUCT_CORRECTION subutility: RAP$SORT_PSRS procedure.' ??
MODULE ram$sort_psrs;

{ PURPOSE:
{   This module contains the procedure to sort an array of psrs.
{
{ DESIGN:
{   The compiled module resides in RAF$LIBRARY.
{
{ NOTES:
{
?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc rat$subproduct_info_types
?? POP ??

?? NEWTITLE := 'Global Declarations Declared by This Module', EJECT ??

?? OLDTITLE ??
?? NEWTITLE := '[XDCL rap$sort_psrs', EJECT ??

{ PURPOSE:
{   This procedure sorts the psr list.
{
{ DESIGN:
{   This procedure uses a shell sort.
{
{ NOTES:
{

  PROCEDURE [XDCL] rap$sort_psrs
    (VAR psr_list: rat$psrs_answered);

    VAR
      current: integer,
      gap: integer,
      start: integer,
      swap: rat$psr;


    gap := UPPERBOUND (psr_list);
    WHILE gap > 1 DO
      gap := 2 * (gap DIV 4) + 1;
      FOR start := LOWERBOUND (psr_list) TO UPPERBOUND (psr_list) - gap DO
        current := start;
        WHILE (current > 0) AND (psr_list [current] > psr_list [current + gap]) DO
          swap := psr_list [current];
          psr_list [current] := psr_list [current + gap];
          psr_list [current + gap] := swap;
          current := current - gap;
        WHILEND;
      FOREND;
    WHILEND;

  PROCEND rap$sort_psrs;

MODEND ram$sort_psrs;
