Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding smallest number 1

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I am trying to see if there's a more efficient algoritm to find the smallest and biggest number in an array.
I have an array that has a size of 101.
Right now i am doing a loop and comparing each values to locate the smallest and largest but the code looks heavy to me and not very efficient.

what would be a good way to do that?
Thanks.
P
 
You can either use the numeric values, (-1,0,1 explained above) or add TYPES to your uses clause.
 
Got it..The original algorithm did give me the correct results but not the updated one. I modified the code like that. Hope this is ok.

for I := (Low(A) + 1) to High(A) do
begin
if CompareValue(A, A[Result.Min]) =
LessThanValue then
Result.Min := I
else
if CompareValue(A, A[Result.Max]) =
GreaterThanValue then
Result.Max := I;
end;

Thanks.
P
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top