Category : Pascal Source Code
Archive   : P_PASCAL.ZIP
Filename : LISTTEST.PAS

 
Output of file : LISTTEST.PAS contained in archive : P_PASCAL.ZIP
(*$c+*)
PROGRAM listtest;
TYPE List_ptr = ^Node;
Node = RECORD
Number : Integer;
Next : List_ptr
END;
VAR First, Current : List_ptr;
i : Integer;
Marker : ^Integer;
BEGIN
{ NOTE: UPPERCASE IS NOT NECESSARY; I JUST LIKE TO USE IT. }
{ --------------------------------------------------------- }
{ In this system, whole blocks of memory are allocated }
{ and deallocated by MARK(^Integer) and RELEASE(^Integer). }
{ MARK() saves the heap state as an Integer pointer BEFORE }
{ allocation using NEW() begins, and RELEASE() restores the }
{ heap to that state after the memory allocated by NEW() is }
{ no longer needed. Note that MARK() and RELEASE() do not }
{ have to appear in the same procedure. All that is needed }
{ is for them to have the same Integer pointer parameter. }
{ ---------------------------------------------------------- }
{ Save the heap address in Marker: }
MARK(Marker);
{ Initialize the list and its pointers: }
NEW(First); First^.Next := NIL;
Current := First;
FOR i := 1 TO 30 DO
BEGIN
{ Add each number to the list; then add a node: }
Current^.Number := i;
NEW(Current^.Next);
Current := Current^.Next;
Current^.Next := NIL
END;
Current := First;
WHILE Current^.Next <> NIL DO
BEGIN
{ Write out the node value: }
WRITE('Current Number: ', Current^.Number : 2,
'; Current^.Next ','is ');
First := Current^.Next;
IF Current^.Next <> NIL THEN WRITE('not ');
WRITE('nil. Current^.Next^.Next is ');
IF Current^.Next^.Next <> NIL THEN WRITE('not ');
WRITELN('nil.');
{ USE OF RELEASE() BELOW MAKES THIS INSTANCE }
{ OF DISPOSE() UNNECESSARY, BUT NOT WRONG: }
DISPOSE(Current);
Current := First
END;
{ RETURN ALL OF THE NEW() NODES TO THE HEAP IN ONE }
{ OPERATION. DISPOSE() ABOVE HAS ALREADY DONE THIS }
{ WORK ONE NODE AT A TIME. IN THIS EXAMPLE, EITHER }
{ DISPOSE() OR RELEASE() IS REDUNDANT, BUT NOT BOTH: }
RELEASE(Marker)
END.


  3 Responses to “Category : Pascal Source Code
Archive   : P_PASCAL.ZIP
Filename : LISTTEST.PAS

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/