Jump to content

Algorithms/Find maximum/vb script method 3

From Wikibooks, open books for an open world

<script type="text/vbscript">

  function findMax(aa,i_intStart,i_intEnd)
     Dim o_intMax
     if  ( (i_intEnd - i_intStart) <= 1.5 ) then
        if ( aa(i_intEnd) > aa(i_intStart) ) then
            o_intMax = aa(i_intEnd)
        else
            o_intMax = aa(i_intStart)
        end if
     else
        Dim p_intJ 
        p_intJ = ( ( ( i_intEnd - i_intStart) + 1 ) / 2) -1      
        if ( p_intJ = 1.5) then
           p_intJ = 1
        end if
        Dim o_intM 
        Dim o_intN 
        o_intM = findMax(aa,i_intStart,i_intStart+p_intJ)
        o_intN = findMax(aa,i_intStart + p_intJ + 1,i_intEnd)
        
        if ( o_intM > o_intN ) then
          o_intMax = o_intM
        else 
          o_intMax = o_intN
        end if
     end if
     findMax = o_intMax
  end function    
  Dim cc(3)
  cc(0) = 9
  cc(1) = 6
  cc(2) = 5
  cc(3) = 1
  document.write("Max is " & findMax(cc,0,3) )    
  </script>