type LL: record Name: string Height: real Link: pointer to LL end record var Head: pointer to LL procedure GetData(FileName: string) var FileNo: int var NewRec, Previous: pointer to LL open: FileNo, FileName, get Previous := nil Head := nil loop exit when eof(FileNo) new NewRec get: FileNo, NewRec->Name, NewRec->Height NewRec->Link := nil if Previous = nil then Head := NewRec else Previous->Link := NewRec end if Previous := NewRec end loop end GetData procedure PrintList var Current: pointer to LL Current := Head loop exit when Current = nil put Current->Name, " ", Current->Height Current := Current->Link end loop end PrintList procedure MoveFront(MH: real) var Previous,Current,Next: ^LL Current := Head Previous := nil loop exit when Current = nil if Current->Height > MH then % move this one to the front % First remove it from where it is in the list (if it isn't % at the head of the list already Next := Current->Link if Previous not = nil then Previous->Link := Next % put at head Current->Link := Head Head := Current % Previous stays same else % If previous was nil, then item was already at head % Just need to make sure previous is set correctly Previous := Current end if Current := Next else % Don't move this one, just continue scanning Previous := Current Current := Current->Link end if end loop end MoveFront % MAIN var FName: string var Command: string var MoveHeight: real % Get the file name containing linked list data from user put "Enter File Name: " .. get FName % Read Data and create Linked List GetData(FName) % Loop to Read Command from user put "Commands are P (display list) M (Move To Front) and Q (quit) " loop put "Command: " .. get Command if Command = "P" or Command = "p" then PrintList elsif Command = "M" or Command = "m" then put "Height of Records to be moved to front: " .. get MoveHeight MoveFront(MoveHeight) elsif Command = "Q" or Command = "q" then exit else put "Unknown Command, ", Command end if end loop