{problem 3 on the 1st midterm. Removes last node on a doubly linked list} type pointer = ^ node; node = record left, right : pointer; info : integer end; var list : pointer; procedure print( list : pointer ); {pre : pointer at the begining of the list post : pointer at the beginning of the list again and list printed} var p : pointer; begin while list <> nil do begin write( list^.info); list:= list^.right end end; function last( list : pointer ) : pointer; {finds the pointer to the last node on a list} begin while list^.right <> nil do list := list ^.right; last := list; end; procedure remove( head : pointer ); var q, previous : pointer; begin q := last( head ); previous := q^.left; previous^.right := nil; writeln('The info in the last node is ', q^.info ) end; procedure generate( var list : pointer); {build doubly-linked linked list} var p1, temp : pointer; j : integer; begin new( list ); list^.left := nil; list ^.info:= 1; temp := list; for j := 2 to 9 do begin new( p1 ); p1^.info := j; temp^.right := p1; p1^.left := temp; temp := p1 end; p1^.right := nil; end; begin generate( list ); print( list ); remove( list ); print( list) end.