Guest User

Untitled

a guest
May 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.28 KB | None | 0 0
  1. {================================================================}
  2. procedure dodaj_jaskinie(tmp:wsk; x:string);
  3.  
  4.   var i:integer;
  5.       na_tmp:wsk;
  6.  
  7.   begin
  8.  
  9.     if tmp=nil then begin
  10.       new(pocz);
  11.       pocz^.nazwa:=x; pocz^.next:=nil;
  12.       pocz^.numerek:=0; pocz^.sasiad:=nil; end
  13.     else begin
  14.       i:=0;
  15.       while (tmp<>nil) and (x>tmp^.nazwa) do begin
  16.         na_tmp:=tmp;
  17.         tmp:=tmp^.next; i:=i+1; end;
  18.  
  19.       if tmp=nil then begin
  20.         new(tmp);
  21.         tmp^.nazwa:=x; tmp^.next:=nil; tmp^.sasiad:=nil;
  22.         tmp^.numerek:=i;
  23.         na_tmp^.next:=tmp; end
  24.       else begin
  25.         if i=0 then begin
  26.           na_tmp:=tmp;
  27.           new(tmp);
  28.           tmp^.nazwa:=x; tmp^.sasiad:=nil;
  29.           tmp^.numerek:=i;
  30.           tmp^.next:=na_tmp;
  31.           pocz:=tmp; end
  32.         else begin
  33.           new(tmp);
  34.           tmp^.nazwa:=x;
  35.           tmp^.numerek:=i; tmp^.sasiad:=nil;
  36.           tmp^.next:=na_tmp^.next;
  37.           na_tmp^.next:=tmp;
  38.         end;
  39.  
  40.         tmp:=tmp^.next;
  41.  
  42.         while tmp<>nil do begin
  43.           tmp^.numerek:=tmp^.numerek+1;
  44.           tmp:=tmp^.next; end;
  45.  
  46.       end;
  47.     end;
  48.  
  49.   end;
  50. {================================================================}
  51.  
  52.  
  53.  
  54. {================================================================}
  55. procedure dodaj_do_sasiedztwa(tmp:wsk; x:string);
  56.  
  57.   var pomoc:wsk;
  58.       i:integer;
  59.       pom,na_pom:sasiedztwo;
  60.  
  61.   begin
  62.     pomoc:=pocz;
  63.     while pomoc^.nazwa<>x do pomoc:=pomoc^.next;
  64.  
  65.     if tmp^.sasiad=nil then begin
  66.       new(tmp^.sasiad);
  67.       tmp^.sasiad^.przejscie:=pomoc;
  68.       tmp^.sasiad^.kolejni:=nil;
  69.       tmp^.sasiad^.numerek:=0; end
  70.     else begin
  71.       i:=0;
  72.       pom:=tmp^.sasiad;
  73.  
  74.       while (pom<>nil) and (x>pom^.przejscie^.nazwa) do begin
  75.         na_pom:=pom;
  76.         pom:=pom^.kolejni; i:=i+1; end;
  77.  
  78.       if pom=nil then begin
  79.         new(pom); pom^.przejscie:=pomoc;
  80.         pom^.kolejni:=nil; pom^.numerek:=i;
  81.         na_pom^.kolejni:=pom; end
  82.       else begin
  83.         if i=0 then begin
  84.           na_pom:=pom;
  85.           new(pom); pom^.przejscie:=pomoc;
  86.           pom^.kolejni:=na_pom; pom^.numerek:=i;
  87.           tmp^.sasiad:=pom; end
  88.         else begin
  89.           new(pom);
  90.           pom^.przejscie:=pomoc; pom^.kolejni:=na_pom^.kolejni;
  91.  
  92.           pom^.numerek:=i; na_pom^.kolejni:=pom;
  93.         end;
  94.  
  95.         pom:=pom^.kolejni;
  96.  
  97.         while pom<>nil do begin
  98.           pom^.numerek:=pom^.numerek+1;
  99.           pom:=pom^.kolejni end;
  100.       end;
  101.     end;
  102.  
  103.   end;
  104. {================================================================}
  105.  
  106.  
  107.  
  108. {================================================================}
  109. procedure wczytaj_labirynt;
  110.  
  111.   var a,b:string;
  112.       poczatek:wsk;
  113.       jestA,jestB:boolean;
  114.       tmp:sasiedztwo;
  115.  
  116.   begin
  117.  
  118.     repeat
  119.       readln(a); readln(b);
  120.       if (length(a)>0) and (length(b)>0) and (a<>b) then begin
  121.  
  122.         poczatek:=pocz;
  123.         jestA:=false; jestB:=false;
  124.  
  125.         while poczatek<>nil do begin
  126.           if poczatek^.nazwa=a then jestA:=true;
  127.           if poczatek^.nazwa=b then jestB:=true;
  128.           poczatek:=poczatek^.next;
  129.         end;
  130.  
  131.         poczatek:=pocz;
  132.         if not jestA then begin
  133.           dodaj_jaskinie(poczatek,a);
  134.         end;
  135.  
  136.         poczatek:=pocz;
  137.  
  138.         if not jestB then begin
  139.           dodaj_jaskinie(poczatek,b);
  140.         end;
  141.  
  142.         poczatek:=pocz; jestA:=false; jestB:=false;
  143.         while poczatek<>nil do begin
  144.           if poczatek^.nazwa=a then begin
  145.             tmp:=poczatek^.sasiad;
  146.             while tmp<>nil do begin
  147.               if tmp^.przejscie^.nazwa=b then jestB:=true;
  148.               tmp:=tmp^.kolejni;
  149.             end;
  150.             if not jestB then dodaj_do_sasiedztwa(poczatek,b);
  151.           end;
  152.  
  153.           if poczatek^.nazwa=b then begin
  154.             tmp:=poczatek^.sasiad;
  155.             while tmp<>nil do begin
  156.               if tmp^.przejscie^.nazwa=a then jestA:=true;
  157.               tmp:=tmp^.kolejni;
  158.             end;
  159.             if not jestA then dodaj_do_sasiedztwa(poczatek,a);
  160.           end;
  161.  
  162.           poczatek:=poczatek^.next;
  163.         end;
  164.  
  165.       end;
  166.  
  167.     until eoln or eof;
  168.  
  169.     if eof then koniec_programu:=true;
  170.     if eoln then readln;
  171.  
  172.   end;
  173. {================================================================}
Add Comment
Please, Sign In to add comment