其他分享
首页 > 其他分享> > 数组index

数组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;
    }

     

标签:even,index,length,数组,中值,Array,odd
来源: https://www.cnblogs.com/dissipate/p/14902593.html