{Generates doubly lnked list from singly linked list} type pointer = ^node; node = record info : integer; next: pointer end {node}; d_pointer = ^d_node; d_node = record info : integer; left, right : d_pointer end {node}; procedure print(t : pointer); {pre : pointer to head of list exists post : list printed and t points at nil} begin if t <> nil then begin writeln( t^.info : 3); print( t^.next ) end end; procedure print2( t : d_pointer); {pre : pointer to head of list exists post : list printed and t points at nil} begin if t <> nil then begin write( t^.info : 3 ); print2( t^.right ) end end; procedure create_list(var list : pointer); var q, p, s : pointer; j : integer; begin new( q); list := q; for j := 1 to 9 do begin q^.info := j; new( p ); q^.next := p; q := p end; q^.info := 10; q^.next := nil; end; { create_list } procedure double(list1 : pointer; var list2 : d_pointer); var q : pointer; p, s, t : d_pointer; begin q := list1; if q = nil then list2 := nil else begin new( p ); {1st node} p^.left := nil; list2 := p; while q <> nil do begin p^.info := q^.info; t := p; new( s ); s^.left := p; p^.right := s; p := s; q := q^.next end; t^.right := nil; dispose( s) end end; var list1 : pointer; list2 : d_pointer; begin {main} create_list( list1 ); writeln('prints the list'); print( list1 ); writeln; double( list1, list2 ); writeln('prints doubly linked list forwards'); print2( list2 ); end.