数据结构-数组详解例子

时间:2016-01-07 14:50:40   收藏:0   阅读:361
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];

技术分享

 

原文:http://www.cnblogs.com/startnow/p/5109812.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!