主题:怎么把这个程序专换成递归的方法?
program A;
type
Next=^zap;
t=string[26];
zap=record
fam:t;
Sled:next;
end;
var
UKSTR,UKZV:Next;
f1:text;
temp:t;tt:boolean;
procedure max(UKstr:next);
var
temp:t;ukzv:next;
begin
Ukzv:=ukstr;
tt:=true;
while tt do
Begin
tt:=false;
While UKZV^.sled<>Nil do
BEGIN
if UKZV^.fam>UKZV^.sled^.fam Then
Begin
tt:=true;
temp:=UKZV^.fam;
UKZV^.fam:=UKZV^.sled^.fam;
UKZV^.sled^.fam:=temp;
end;
ukzv:=ukzv^.sled;
end;
ukzv:=ukstr
END;
End;
begin
assign(f1,'dan5.txt');
reset(f1);
assign(output,'res5.out');
rewrite(output);
new(UKZV);
UKSTR:=UKZV;
Readln(f1,UKZV^.fam);
UKZV^.Sled:=Nil;
While Not Eof(f1) do
Begin
new(UKZV^.sled);
UKZV:=UKZV^.sled;
readln(f1,UKZV^.fam);
UKZV^.sled:=nil;
end;
UKZV:=UKSTR;
While UKZV<>Nil do
Begin
writeln(UKZV^.fam);
UKZV:=UKZV^.sled;
end;
close(f1);
ukzv:=ukstr;
max(UKZV);
writeln('====================');
UKZV:=ukstr;
While UKZV<>Nil do
Begin
writeln(UKZV^.fam);
UKZV:=UKZV^.sled;
end;
close(output);
end.
type
Next=^zap;
t=string[26];
zap=record
fam:t;
Sled:next;
end;
var
UKSTR,UKZV:Next;
f1:text;
temp:t;tt:boolean;
procedure max(UKstr:next);
var
temp:t;ukzv:next;
begin
Ukzv:=ukstr;
tt:=true;
while tt do
Begin
tt:=false;
While UKZV^.sled<>Nil do
BEGIN
if UKZV^.fam>UKZV^.sled^.fam Then
Begin
tt:=true;
temp:=UKZV^.fam;
UKZV^.fam:=UKZV^.sled^.fam;
UKZV^.sled^.fam:=temp;
end;
ukzv:=ukzv^.sled;
end;
ukzv:=ukstr
END;
End;
begin
assign(f1,'dan5.txt');
reset(f1);
assign(output,'res5.out');
rewrite(output);
new(UKZV);
UKSTR:=UKZV;
Readln(f1,UKZV^.fam);
UKZV^.Sled:=Nil;
While Not Eof(f1) do
Begin
new(UKZV^.sled);
UKZV:=UKZV^.sled;
readln(f1,UKZV^.fam);
UKZV^.sled:=nil;
end;
UKZV:=UKSTR;
While UKZV<>Nil do
Begin
writeln(UKZV^.fam);
UKZV:=UKZV^.sled;
end;
close(f1);
ukzv:=ukstr;
max(UKZV);
writeln('====================');
UKZV:=ukstr;
While UKZV<>Nil do
Begin
writeln(UKZV^.fam);
UKZV:=UKZV^.sled;
end;
close(output);
end.