╪azenφ dat - algoritmy a °adφcφ metody | |
21. prosince 1998 | skrivan@fi.muni.cz |
var i, j, k: index; x, pom: prvek; a: array [index] of prvek; begin for j:=1 to n do begin x:=a[j]; k:=j; for i:=j+1 to n do if x<a[i] then begin x:=a[i]; k:=i; end; pom:=a[i]; a[i]:=a[k]; a[k]:=pom; inc(j); end; end. |
var i, j: index; x: prvek; a: array [index] of prvek; begin for i:=2 to n do begin x:=a[i]; a[0]:=x; j:=i-1; while x<a[j] do begin a[j+1]:=a[j]; dec(j); end; a[j+1]:=x; end; end. |
var a: array [index] of prvek; n: index; procedure rozdel(l: index; var i,j: index; r: index); var w: prvek; begin i:=l; j:=r; x:=a[(l+r) div 2]; repeat while a[i]<x do inc(i); while x<a[j] do dec(j); if i<=j then begin w:=a[i]; a[i]:=a[j]; a[j]:=w; inc(i); dec(j); end; until i>j; end; procedure trid(l,r: index); var i,j: index; begin rozdel(l,i,j,r); if l<j then trid(l,j); if i<r then trid(i,r); end; BEGIN trid(1,n); END. |
var i,j: index; x: prvek; a: array [index] of prvek; begin for i:=2 to n do for j:=n downto i do if a[j-1]>a[j] then begin x:=a[j-1]; a[j-1]:=a[j]; a[j]:=x; end; end. |
[Zp∞t] | [Zm∞na k≤dovßnφ] | [StromeΦek] |