Sign in to follow this  
Followers 0
ezzetabi

Find Min and Max in one pass.

2 posts in this topic

Func _MaxMin(ByRef $aArray, ByRef $vMin, ByRef $vMax)
    Local $c, $iSp
    If Mod(UBound($aArray), 2) = 0 Then
        $iSp = 2
      If $aArray[0] < $aArray[1] Then
         $vMin = $aArray[0]
         $vMax = $aArray[1]
      Else
         $vMin = $aArray[1]
         $vMax = $aArray[0]
      EndIf
   Else
      $iSp = 1
      $vMin = $aArray[0]
      $vMax = $aArray[0]
    EndIf
   For $c = $iSp To UBound($aArray) - 1 Step 2
      If $aArray[$c] < $aArray[$c + 1] Then
         If $aArray[$c] < $vMin Then
            $vMin = $aArray[$c]
         EndIf
         If $aArray[$c + 1] > $vMax Then
            $vMax = $aArray[$c + 1]
         EndIf
      Else
         If $aArray[$c + 1] < $vMin Then
            $vMin = $aArray[$c + 1]
         EndIf
         If $aArray[$c] > $vMax Then
            $vMax = $aArray[$c]
         EndIf
      EndIf
   Next
EndFunc

Share this post


Link to post
Share on other sites



Cool idea! One thinig though - I'd suggest you adjust your comparison routine to match that of the _ArraySort routines, as far the ability to compare INTs to Strings, etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0