home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / sigmv022.ark / POINT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-04-29  |  1.3 KB  |  58 lines

  1.  
  2. (******************************************************
  3. *
  4. *        POINTERS
  5. *
  6. *    This program will input a list of names, store
  7. *    them in a linked list, output the list, release
  8. *    the storage and end.  It is a demo program but
  9. *    can be expanded to just about anything.
  10. *
  11. *    Extracted from the Pascal/Z manual, page 49.
  12. *
  13. *    Editor for this program was Charlie Foster
  14. *    June 1980
  15. *******************************************************)
  16.  
  17. PROGRAM pointers;
  18.  
  19. TYPE    link    = ^namerec;
  20.     namerec = RECORD
  21.             name : string 20;
  22.             next : link
  23.             END;
  24.  
  25. VAR    m1    : link;    { FOR STORING THE MARK }
  26.     first : link;    { FOR FINDING THE FIRST NAME }
  27.     last  : link;    { FOR FINDING THE LAST NAME }
  28.     x     : link;    { FOR CHASING THROUGH THE LIST }
  29.  
  30. BEGIN
  31.     MARK(m1);    { MARK SETS POINTER TO TOP/HEAP }
  32.     first := nil;    { 1st NAME POINTER=0 }
  33.     REPEAT
  34.         IF first = nil THEN
  35.            BEGIN
  36.             NEW(last);    { ALLOCATE A NEW REC }
  37.             first := last
  38.            END
  39.         ELSE
  40.            BEGIN
  41.             NEW(last^.next);
  42.             last := last^.next
  43.            END;
  44.         WRITE('Name (* = Done )');
  45.         READLN(last^.name);    { GET PERSONS NAME }
  46.         last^.next := nil
  47.     UNTIL last^.name ='*';
  48. { PRINT OUT THE NAMES }
  49.     x := first;
  50.     WHILE x^.next <> nil DO
  51.        BEGIN
  52.         WRITELN(x^.name);
  53.         x := x^.next
  54.        END;
  55. { RESTORE THE STORAGE }
  56.     RELEASE(m1);
  57. END.
  58.