diff options
author | Erich Eckner <git@eckner.net> | 2016-03-30 15:53:17 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2016-03-30 15:53:17 +0200 |
commit | de1027d1efa77051fa0b3b942212e7f2f72f2d40 (patch) | |
tree | 7c3a1ec4a193707876da8bd8f1afdbdd2e216d3d | |
parent | 7e8fb97b1985e7bbea1d55f4259ffe12ab37f724 (diff) | |
download | units-de1027d1efa77051fa0b3b942212e7f2f72f2d40.tar.xz |
fuegeSortiertHinzu neu in lowlevelunit.pas
-rw-r--r-- | lowlevelunit.pas | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lowlevelunit.pas b/lowlevelunit.pas index 52786db..940e4bc 100644 --- a/lowlevelunit.pas +++ b/lowlevelunit.pas @@ -101,6 +101,7 @@ function myUtf8Encode(s: string): string; function permutation(len: longint): tLongintArray; overload; function permutation(len,rest,maxBasis: longint; basen: tLongintArray): tLongintArray; overload; procedure llPermutation(len,offset: longint; var ar: tLongintArray); inline; +procedure fuegeSortiertHinzu(x: extended; var xa: tExtendedArray); var base64Chars: array[0..63] of char; @@ -923,6 +924,29 @@ begin fehler('permutation: '+inttostr(i)+' wurde nicht verteilt!'); end; +procedure fuegeSortiertHinzu(x: extended; var xa: tExtendedArray); +var + mi,ma,i: longint; +begin + mi:=0; + ma:=length(xa)-1; + while mi<=ma do begin + i:=(mi+ma) div 2; + if x<xa[i] then + ma:=i-1 + else if x>xa[i] then + mi:=i+1 + else + exit; + end; + if mi<>ma+1 then + fehler('Bisektion fehlgeschlagen! ('+inttostr(mi)+' = mi <> ma+1 = '+inttostr(ma+1)+')'); + setlength(xa,length(xa)+1); + for i:=length(xa)-1 downto mi+1 do + xa[i]:=xa[i-1]; + xa[mi]:=x; +end; + var b: byte; |