summaryrefslogtreecommitdiff
path: root/lowlevelunit.pas
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-03-30 15:53:17 +0200
committerErich Eckner <git@eckner.net>2016-03-30 15:53:17 +0200
commitde1027d1efa77051fa0b3b942212e7f2f72f2d40 (patch)
tree7c3a1ec4a193707876da8bd8f1afdbdd2e216d3d /lowlevelunit.pas
parent7e8fb97b1985e7bbea1d55f4259ffe12ab37f724 (diff)
downloadunits-de1027d1efa77051fa0b3b942212e7f2f72f2d40.tar.xz
fuegeSortiertHinzu neu in lowlevelunit.pas
Diffstat (limited to 'lowlevelunit.pas')
-rw-r--r--lowlevelunit.pas24
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;