跳至内容

算法/查找最大值/javascript 方法 5

来自 Wikibooks,开放世界的开放书籍

<script language="javascript">

  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>
华夏公益教科书