{ Here is the code I showed you in class on Monday. Strings are stored as linked lists of characters (that is, each node in the list contains a character and a pointer to the next node). } program stringsAsLists(input,output); type nodePtr = ^node; node = record data : char; next : nodePtr end; var message : nodePtr; { ReadString reads characters from the keyboard until reaching the end of a line. The characters are put into a linked list, with str pointing to the head of the list (which is also the first character read). } procedure ReadString( var str : nodePtr ); var currentNode : nodePtr; begin if eoln then str := nil else begin new( currentNode ); read( currentNode^.data ); str := currentNode; while not eoln do begin new( currentNode^.next ); currentNode := currentNode^.next; read( currentNode^.data ) end; currentNode^.next := nil end end; { WriteString prints a string stored as a linked list of characters. } procedure WriteString( str : nodePtr ); var currentNode : nodePtr; begin currentNode := str; while currentNode <> nil do begin write( currentNode^.data ); currentNode := currentNode^.next end end; procedure WriteBackwards( str : nodePtr ); begin if str <> nil then begin WriteBackwards( str^.next ); write( str^.data ) end end; begin write( 'Type something: ' ); ReadString( message ); write( 'You typed: ' ); WriteString( message ); writeln; write( 'Here it is, backwards: ' ); WriteBackwards( message ); writeln end.