Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Algorithmen (https://www.delphipraxis.net/28-library-algorithmen/)
-   -   Delphi Max/Min mit mehreren Werten (https://www.delphipraxis.net/74620-max-min-mit-mehreren-werten.html)

DGL-luke 6. Aug 2006 16:25


Max/Min mit mehreren Werten
 
Hallo,

ich hab in der Codelib noch nichts entsprechendes gefunden, deswegen poste ich es hier mal.

Alternativ kann man die Methoden MaxIntValue/MinIntValue bzw. MaxValue/MinValue aus der Unit Math verwenden.s

Delphi-Quellcode:
function Max(const Values: array of Integer): Integer;
var I: Integer;
begin
  Result := Values[0];
  for i := 1 to high(Values) do
    begin
      if Values[i] > Result then
        Result := Values[i];
    end;
end;

function Min(const Values: array of Integer): Integer;
var I: Integer;
begin
  Result := Values[0];
  for i := 1 to high(Values) do
    begin
      if Values[i] < Result then
        Result := Values[i];
    end;
end;

function Max(const Values: array of Double): Double;
var I: Integer;
begin
  Result := Values[0];
  for i := 1 to high(Values) do
    begin
      if Values[i] > Result then
        Result := Values[i];
    end;
end;

function Min(const Values: array of Double): Double;
var I: Integer;
begin
  Result := Values[0];
  for i := 1 to high(Values) do
    begin
      if Values[i] < Result then
        Result := Values[i];
    end;
end;
Muss natürlich mit overload; im Kopf der Unit (also in implementation) deklariert werden.

[edit=Chakotay1308]Hinweis zu vorhandenen Routinen angefügt. Mfg, Chakotay1308[/edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:07 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz