program ex5; uses crt; type tree=^rec1; rec1=record inf:string[10]; lf,rt:tree end; tlist=^rec2; rec2=record inf:string[10]; next:tlist end; var gltree:tree; head,p1:tlist; f1:text; q1:boolean; procedure put_tree(var root:tree; inp:string); var p,prev:tree; f:text; s:string; begin assign(f,inp); reset(f); if eof(f) then root:=nil else begin new(root); readln(f,root^.inf); root^.lf:=nil; root^.rt:=nil; end; while not eof(f) do begin p:=root; readln(f,s); while p<>nil do begin prev:=p; if s<=p^.inf then p:=p^.lf else p:=p^.rt end; new(p); p^.lf:=nil; p^.rt:=nil; p^.inf:=s; if p^.infnil then print_tree(p^.lf); writeln(p^.inf); if p^.rt<>nil then print_tree(p^.rt) end; procedure make_sortlist(t:tree; var first,p: tlist; var q:boolean); begin if t^.lf<>nil then make_sortlist(t^.lf,first,p,q); new(p^.next); p:=p^.next; p^.inf:=t^.inf; p^.next:=nil; if q=false then begin first:=p; q:=true end; if t^.rt<>nil then make_sortlist(t^.rt,first,p,q); end; begin clrscr; put_tree(gltree,'input5.inp'); print_tree(gltree); p1:=nil; q1:=false; make_sortlist(gltree,head,p1,q1); assign(f1,'output5.out'); rewrite(f1); p1:=head; while p1<>nil do begin writeln(f1,p1^.inf); p1:=p1^.next end; close(f1) end.