{<<<< Builder >>>>}
{ From: COMPLETE TURBO PASCAL by Jeff Duntemann  }
{ Scott, Foresman & Co. 1986  ISBN 0-673-18600-8 }
{ Described in section 19.2 -- Last mod 2/1/86   }

PROCEDURE Builder(VAR Root : NADPtr; WorkRec : NADRec);

VAR 
  Current,Last : NADPtr;

BEGIN
  IF Root = Nil THEN      { List is empty! }
    BEGIN
      New(Root);
      WorkRec.Next := Nil;
      Root^ := WorkRec
    END
  ELSE                    { List already contains some records }
    BEGIN
      Current := Root;
      REPEAT              { Traverse list to find correct spot }
        Last := Current;
        Current := Current^.Next
      UNTIL (Current = Nil) OR (Current^.Name > WorkRec.Name)
                          { Found spot--now insert new record  }
      IF Root^.Name > WorkRec.Name THEN   { Record becomes new }
        BEGIN                             { first item on list }
          New(Root);              { Create new record for Root }
          WorkRec.Next := Last;   { Copy root pointer to Next  }
          Root^ := WorkRec        { Copy WorkRec to new record }
        END
      ELSE                                { Record belongs in  }
        BEGIN                             { mid-list somewhere }
          New(Last^.Next);         { Create new record for Last}
          WorkRec.Next := Current; { Point new rec to Current  }
          Last^.Next := WorkRec;   { Copy WorkRec to new record}
        END
    END
END;
