Einzelnen Beitrag anzeigen

Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#1

Max/Min mit mehreren Werten

  Alt 6. Aug 2006, 16:25
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]
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat