Hususiyati
|
Qiymati
|
Hususiyati
|
Qiymati
|
Name
|
StringGrid1
|
FixedRows
|
1
|
ColCount
|
11
|
Options . goEditing
|
TRUE
|
RowCount
|
11
|
DefaultColWidth
|
16
|
FixedCols
|
1
|
DefaultRowHeight
|
14
|
Bu masala dasturining matni 13.5- listingda keltirilgan.
13.5-listing. Marshrutni qidirish.
procedure TForm1.FormActivate(Sender: TObject);
var
i:integer;
begin
satrlarni nomerlash
for I : 1 to 10 do
StringGrid1.Cells[0,i] : IntToStr(i);
ustunlarni nomerlash
for I : 1 to 10 do
StringGrid1.Cells[i,0] : IntToStr(i);
xarita
StringGrid1.Cells[1,2] : '1'; StringGrid1.Cells[2,1] : '1';
StringGrid1.Cells[1,3] : '1'; StringGrid1.Cells[3,1] : '1';
StringGrid1.Cells[1,4] : '1'; StringGrid1.Cells[4,1] : '1';
StringGrid1.Cells[3,7] : '1'; StringGrid1.Cells[7,3] : '1';
StringGrid1.Cells[4,6] : '1'; StringGrid1.Cells[6,4] : '1';
StringGrid1.Cells[5,6] : '1'; StringGrid1.Cells[6,5] : '1';
StringGrid1.Cells[5,7] : '1'; StringGrid1.Cells[7,5] : '1';
StringGrid1.Cells[6,7] : '1'; StringGrid1.Cells[7,6] : '1';
end;
procedure TForm1.Button1Click(Sender: TObject);
const
N10;{ graf uchlarining soni}
var
map: array[1..N,1..N]of integer;
road: array[1..N] of integer;
incl: array[1..N] of boolean;
start, finish: integer; { boshlang’ich va oxirgi nuqtalar }
found: boolean;
i, j: integer;
procedure step(s, f, p:integer);
var
c : integer;{ Navbatdagi qadam qo`yiladigan nuqta nomeri}
I : integer;
begin
if s f then
begin
{ s va f nuqtalar ustma-ust tushmaydi!}
found : TRUE;
Label1.caption : Label1.caption #13 'Yo`l:';
for i : 1 to p-1 do
Label1.caption : Label1.caption ' ' ntToStr(road[i]);
end
else begin
{ navbatdagi nuqta tanlanadi }
for c : 1 to N do
begin {hamma uchlar tekshiriladi }
if(map[s,c]<> 0)and(NOT incl[c])
{nuqta joriy nuqta bilan birlashgan, ammo yo`lga kirmagan}
then begin
road[p] : c;{ uchni yo`lga qo`shamiz }
incl[c]:TRUE; {uchni yo`lga kirgan deb belgilanadi}
step(c, f, p 1);
incl[c] : FALSE;
road[p] : 0;
end;
end;
end;
end;{ step protsedurasi tamom}
begin
Label1.caption : '';
{ massiv elementlarini aniqlash }
for i : 1 to N do road[i] : 0;
for i : 1 to N do incl[i] : FALSE;
for i : 1 to N do
for j : 1 to N do
if StringGrid1.Cells[i,j] <> ''
then map[i,j] : StrToInt(StringGrid1.Cells[i,j])
else map[i,j] : 0;
start : StrToInt(Edit1.text);
finish : StrToInt(Edit2.text);
road[1] : start;{ nuqtani marshrut kiritamiz}
incl[start]: TRUE;{ uni marshrutga kirgan deb belgilanadi }
step(start, finish, 2);{yo`lning ikkinchi nuqtasi aniqlanadi}
hech bo`lmasa bitta yo`l topilganligini tekshiramiz
if not found then
Label1.caption: 'Berilgan quqtalar orasida yo`l yo`q !';
end;
Dastur ishga tushgani, formaning faollashishi davrida OnActivate protsedurasi StringGrid1.cells massivini xaritadagi qiymatlar bilan to`ldiradi xamda fiksirlangan birinchi ustun va satr yacheykalarini to`ldirgan holda nomerlaydi.
Marshrutni Tform1.Button1Click protsedurasi qidiradi. U boshlang’ich nuqta bilan tutashtirilgan nuqtani topish uchun step protsedurasini chaqiradi. Bu protsedura boshlang’ich nuqta bilan tutashgan birinchi nuqtani tanlab, marshrutga qo`shganidan keyin o`zini-o`zi chaqiradi. Bunda boshlang’ich nuqta sifatida berilgan nuqta emas, balki marshrutga hozirgina kiritilgan joriy nuqta olinadi.
Keltirilgan graf uchun dastur natijasi 13.13-rasmda ko`rsatilgan.
13.13-rasm. Dasturning dialog oynasidagi natijalar
Do'stlaringiz bilan baham: |