Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {================================================================}
- procedure dodaj_jaskinie(tmp:wsk; x:string);
- var i:integer;
- na_tmp:wsk;
- begin
- if tmp=nil then begin
- new(pocz);
- pocz^.nazwa:=x; pocz^.next:=nil;
- pocz^.numerek:=0; pocz^.sasiad:=nil; end
- else begin
- i:=0;
- while (tmp<>nil) and (x>tmp^.nazwa) do begin
- na_tmp:=tmp;
- tmp:=tmp^.next; i:=i+1; end;
- if tmp=nil then begin
- new(tmp);
- tmp^.nazwa:=x; tmp^.next:=nil; tmp^.sasiad:=nil;
- tmp^.numerek:=i;
- na_tmp^.next:=tmp; end
- else begin
- if i=0 then begin
- na_tmp:=tmp;
- new(tmp);
- tmp^.nazwa:=x; tmp^.sasiad:=nil;
- tmp^.numerek:=i;
- tmp^.next:=na_tmp;
- pocz:=tmp; end
- else begin
- new(tmp);
- tmp^.nazwa:=x;
- tmp^.numerek:=i; tmp^.sasiad:=nil;
- tmp^.next:=na_tmp^.next;
- na_tmp^.next:=tmp;
- end;
- tmp:=tmp^.next;
- while tmp<>nil do begin
- tmp^.numerek:=tmp^.numerek+1;
- tmp:=tmp^.next; end;
- end;
- end;
- end;
- {================================================================}
- {================================================================}
- procedure dodaj_do_sasiedztwa(tmp:wsk; x:string);
- var pomoc:wsk;
- i:integer;
- pom,na_pom:sasiedztwo;
- begin
- pomoc:=pocz;
- while pomoc^.nazwa<>x do pomoc:=pomoc^.next;
- if tmp^.sasiad=nil then begin
- new(tmp^.sasiad);
- tmp^.sasiad^.przejscie:=pomoc;
- tmp^.sasiad^.kolejni:=nil;
- tmp^.sasiad^.numerek:=0; end
- else begin
- i:=0;
- pom:=tmp^.sasiad;
- while (pom<>nil) and (x>pom^.przejscie^.nazwa) do begin
- na_pom:=pom;
- pom:=pom^.kolejni; i:=i+1; end;
- if pom=nil then begin
- new(pom); pom^.przejscie:=pomoc;
- pom^.kolejni:=nil; pom^.numerek:=i;
- na_pom^.kolejni:=pom; end
- else begin
- if i=0 then begin
- na_pom:=pom;
- new(pom); pom^.przejscie:=pomoc;
- pom^.kolejni:=na_pom; pom^.numerek:=i;
- tmp^.sasiad:=pom; end
- else begin
- new(pom);
- pom^.przejscie:=pomoc; pom^.kolejni:=na_pom^.kolejni;
- pom^.numerek:=i; na_pom^.kolejni:=pom;
- end;
- pom:=pom^.kolejni;
- while pom<>nil do begin
- pom^.numerek:=pom^.numerek+1;
- pom:=pom^.kolejni end;
- end;
- end;
- end;
- {================================================================}
- {================================================================}
- procedure wczytaj_labirynt;
- var a,b:string;
- poczatek:wsk;
- jestA,jestB:boolean;
- tmp:sasiedztwo;
- begin
- repeat
- readln(a); readln(b);
- if (length(a)>0) and (length(b)>0) and (a<>b) then begin
- poczatek:=pocz;
- jestA:=false; jestB:=false;
- while poczatek<>nil do begin
- if poczatek^.nazwa=a then jestA:=true;
- if poczatek^.nazwa=b then jestB:=true;
- poczatek:=poczatek^.next;
- end;
- poczatek:=pocz;
- if not jestA then begin
- dodaj_jaskinie(poczatek,a);
- end;
- poczatek:=pocz;
- if not jestB then begin
- dodaj_jaskinie(poczatek,b);
- end;
- poczatek:=pocz; jestA:=false; jestB:=false;
- while poczatek<>nil do begin
- if poczatek^.nazwa=a then begin
- tmp:=poczatek^.sasiad;
- while tmp<>nil do begin
- if tmp^.przejscie^.nazwa=b then jestB:=true;
- tmp:=tmp^.kolejni;
- end;
- if not jestB then dodaj_do_sasiedztwa(poczatek,b);
- end;
- if poczatek^.nazwa=b then begin
- tmp:=poczatek^.sasiad;
- while tmp<>nil do begin
- if tmp^.przejscie^.nazwa=a then jestA:=true;
- tmp:=tmp^.kolejni;
- end;
- if not jestA then dodaj_do_sasiedztwa(poczatek,a);
- end;
- poczatek:=poczatek^.next;
- end;
- end;
- until eoln or eof;
- if eof then koniec_programu:=true;
- if eoln then readln;
- end;
- {================================================================}
Add Comment
Please, Sign In to add comment