G
guzhengyi_nj
Unregistered / Unconfirmed
GUEST, unregistred user!
有劳大家帮我看看,怎么改成非递归?
谢谢!
function TForm1.getpath(r1, r2, p1: string):boolean;
var
num,i:integer;
qu:TADOQuery;
p3,sql,temp,p2:string;
begin
qu:=TADOQuery.Create(application);
qu.Close ;
qu.sql.clear;
sql:='select * from AllIPConn where router1='''+r1+'''';
qu.SQL.Add(sql);
qu.Connection:=ADOConnection2;
qu.open;
num:=qu.RecordCount ;
if num>0 then
begin
for i := 0 to num-1 do
begin
p3:=p1;
temp:=qu.FieldByName('router2').AsString ;
if trim(temp)=r2 then
begin
result:=true;
exit;
end
else
begin
p3:=p3+'-'+temp;
qu.Next ;
getpath(temp,r2,p3);
end;
end;
end
else
result:=false;
end;
谢谢!
function TForm1.getpath(r1, r2, p1: string):boolean;
var
num,i:integer;
qu:TADOQuery;
p3,sql,temp,p2:string;
begin
qu:=TADOQuery.Create(application);
qu.Close ;
qu.sql.clear;
sql:='select * from AllIPConn where router1='''+r1+'''';
qu.SQL.Add(sql);
qu.Connection:=ADOConnection2;
qu.open;
num:=qu.RecordCount ;
if num>0 then
begin
for i := 0 to num-1 do
begin
p3:=p1;
temp:=qu.FieldByName('router2').AsString ;
if trim(temp)=r2 then
begin
result:=true;
exit;
end
else
begin
p3:=p3+'-'+temp;
qu.Next ;
getpath(temp,r2,p3);
end;
end;
end
else
result:=false;
end;