数据结构-数组详解例子

struct Array
{
   ElemType *base;    /* 数组元素基址,由InitArray分配 */
   int dim;           /* 数组维数 */
   int *bounds;       /* 数组维界基址,由InitArray分配 */
   int *constants;    /* 数组映象函数常量基址,由InitArray分配 */
};
对于三维数组a[3][2][2]

base 是存储数组元素的指针,其指向的内存存储着: a[0][0][0] , a[0][0][1], a[0][1][0].........
dim  维数,存着: 3
bound 指向的内存存着: 3 2 2  //这个就是[3][2][2]
constants 指向的内存存着: 4 2 1  // contants[2]=1        contants[1]= 1 x 2 =2         contants[0]= 2 x 2 =4 

constants[]的计算.
constants[dim-1]=1;
for(i=dim-2; i>=0; i--)
  constants[i] = bound[i+1] * constants[i+1];

 

posted @ 2016-01-07 14:38  一支小白  阅读(694)  评论(0编辑  收藏  举报