found:boolean; i,j:integer;
procedure step(s,f,p:integer);
Var
c:integer;
i:integer;
begin
if s=f then begin
found:=TRUE;
180
Label4.caption:=Label4.caption+#13+'Yoi:';
for i:=l to p-1 do
Label4.caption:=Label4.caption+'
+IntToStr(rgad[i]); end
else begin
for c:=l to N do
begin
if(map[s,c]<> 0)and(NOT incl[c])
then begin
road[p]:=c;
incl[c]:=TRUE;
step(c,f,p+l); incl[c]:=FALSE; rgad[p]:=0;
end;
end;
end;
end;
Begin
Labell.caption:=' ';
for i:=l to N do rgad[i]:=0;
for i:=l to N do incl[i]:=FALSE;
for i:=l to N do
for j:=l to N do
if StringGridl.Cells[i,j] <> "
then map[i,j]:=StrToInt(StringGridl.Cells[i, j])
else map[ij]:=0;
start:=StrToInt(Editl.text);
finish:= StrToInt(Edit2.text);
road[l]:=start;
incl[start] :=TRUE;
step(start,finish,2);
if not found
then Labell.caption:='Nuqtalar tutashtirilmagan';
end;
end.
Eng qisqa yo‘l topish
Eng qisqa yo‘ltopish uchun quyidagi usuldan foydalanish mumkin.
Awal eng birinchi marshrut topib olinadi va u eng qisqa yo‘l deb
qaraladi. Yangi yo‘l izlash davomida, biror nuqtani marshrutga qo‘shish
181
natijasida marshrut uzunligi oldin topilgan yoldan oshib ketsa, bu
nuqta o‘tkazib yuborilib, keyingisi tekshiriladi. Shunday qilib, har bir
topilgan yo‘l oldingisidan qisqaroq boladi.
Quyida shu usulni amalga oshiruvchi dastur matni berilgan:
Dostları ilə paylaş: |