Jump to content

Algorithms/Find maximum/Java findMax method 5

From Wikibooks, open books for an open world

private int[] sorting(int[] i_intaryTb) {

    boolean p_blnFound = true;
    while ( p_blnFound ) {
       p_blnFound = false;
       for (int p_intI =0 ; p_intI < i_intaryTb - 1; p_intI++) {
          if ( i_intaryTb[p_intI] > i_intaryTb[p_intI + 1] ) {
             int p_intTmp         = i_intaryTb[p_intI]   ;
             i_intaryTb[p_intI]   = i_intaryTb[p_intI+1] ;
             i_intaryTb[p_intI+1] = p_intTmp             ;
             p_blnFound = true;
          } // end if            
       } // end loop
    } // end loop
    return i_intaryTb;
 } // end method
 public int findMax(int[] i_intaryTb) {
    int[] o_intaryTb =  sorting(i_intaryTb);
    return o_intaryTb[o_intaryTb.length - 1];
 } // end method