数组的顺序表示和实现
struct SqArray
{
int * base
int dim;
int * bounds;
int * constants;
int elemtotal
}A;
InitArray(struct SqArray * A,int dim,va_list ap)/*va_list is a list type can contain variable elements*/
{
int i;
int p = dim;
if (dim <1 || dim > MAX_ARRAY_DIM)
{
printf("The dimension %d you input is overflow!/n",dim);
return 0;
}
A->dim = dim;
A->bounds = (int *)malloc(dim *sizeof(int));
if (!A->bounds) exit(OVERFLOW);
A->elemtotal = 1;
va_start(ap,dim);
for (i=0;i<dim;++i)
{
A->bounds[i] = va_arg(ap,int);
if (A->bounds[i]<0) exit(OVERFLOW);
A->elemtotal *= A->bounds[i];
}
va_end(ap);
A->base = (int *)malloc(A->elemtotal * sizeof(int));
if (!A->base) exit(OVERFLOW);
A->constants = (int *)malloc(dim* sizeof(int));
if (!A->constants)
A->constants[dim-1]=1;
for(i = dim-2;i>=0;--i)
A->constants[i] = A->bounds[i+1]*A->constants[i+1];
return OK;
}
这个算法里面很多不懂,像int*bounds;
int * constants;
int elemtotal;
A->constants[i] = A->bounds[i+1]*A->constants[i+1];
这些究竟代表了数组的什么,求解释,或者推荐一本书给我又详细介绍的