数组index

  

  1. (Array.length-1)/ 2      and         Array.length/2 取中值 index
    Array.length is even
    
    * * *  * * *
        ^
        (Array.length-1)/2
    
    * * *  * * *
           ^
           Array.length/2
    
    当Array.length is even, -1 对中值index有影响
    
    
    Array.length is odd
    
    * *  *  * *
         ^
         (Array.length-1)/2 == Array.length/2
    
    当Array.length is odd, -1 对中值index无影响
    
    example:
    
    1: reverse Array
    for(int i=0;i<array.length/2;++i){
      int tmp=array[array.length-1-i];
      array[array.length-1-i]=array[i];
      array[i]=tmp;
    }

     

上一篇:Bad habits : Putting NOLOCK everywhere


下一篇:软连接ln