% Program to read in real numbers and store in a linked list % Type Declaration of Record type LinkedList: record Data: real Link: pointer to LinkedList end record % Pointers needed for head of list, and creation of records, and linking var Head, Current, Last: pointer to LinkedList var InData: real % Initially the linked list is empty, so set the Head of list pointer to nil Head := nil % Read in data in a loop, create a new record to hold it and join to linked % list put "Enter Data, finish with a -1.0:" .. loop get InData exit when InData = -1.0 % Allocate a new record to hold data new Current % Fill up the new record with data Current->Data := InData % Set Link to nil because this record will be at the end of % the list, for now Current->Link := nil % Attach to end of list; must check to see if list is empty if Head = nil then % list was empty Head := Current else % this is the 2nd time through loop, so Last will be set to % previous record created Last->Link := Current end if Last := Current end loop % Loop to print out the entire list Current := Head put "The list of numbers is: " .. loop exit when Current = nil put Current->Data, " " .. Current := Current->Link end loop