转到内容

算法/如何寻找最大值/jscript 5

来自维基百科,面向开放世界的开放书籍

<script language="jscript">

  function sorting(i_intaryTb) {
    var p_blnFound = true;
    while ( p_blnFound ) {
        p_blnFound = false;
        for ( var p_intI = 0; p_intI < (i_intaryTb.length - 1) ; p_intI += 1) {
            if ( i_intaryTb[p_intI] > i_intaryTb[p_intI + 1] ) {
               var intTmp             = i_intaryTb[p_intI];
               i_intaryTb[p_intI    ] = i_intaryTb[p_intI+1];
               i_intaryTb[p_intI + 1] = intTmp;
               p_blnFound = true;
            } // end if
        } // end loop
    } // end while
    return i_intaryTb;
  } // end function
  function findMax(i_intaryTb) {
      i_intaryTb = sorting(i_intaryTb);
      return i_intaryTb[i_intaryTb.length - 1];
   } // end method   
  var cc = new Array(3,40,5);
  document.write(findMax(cc));
  </script>
华夏公益教科书