# 資料結構 major運算

(a)Obtain an addressing formula for the element A[i1][i2] in an aray declared as A[u1][u2]. Assume a row-major representation of the array with one word per element and α the address of A[0][0].

(b)Obtain an addressing formula for the element A[i1][i2] in an aray declared as B[u1][u2]. Assume a column-major representation of the array with one word per element and β the address of A[0][0].

(c)Obtain an addressing formula for the element A[i1][i2][i3] in an aray declared as B[u1][u2][u3]. Assume a row-major representation of the array with one word per element and δ the address of A[0][0][0].

(d)Obtain an addressing formula for the element A[i1][i2][i3] in an aray declared as B[u1][u2][u3]. Assume a column-major representation of the array with one word per element and γ the address of A[0][0][0].

Rating
• Leslie
Lv 7

假設宣告 A[u1][u2]([u3]) 是指

A 的列標 0 to (u1-1), 行標 0 to (u2-1) (且深度標 0 to (u3-1)).

(您的題目中, array B 應為 array A)

(a)

A[i1,i2] 的上面, 有 i1 個列, 共 i1*u2 個元素;

A[i1,i2] 所在的這一列, A[i1,i2] 的左方有 i2 個元素;

因此 A[i1,i2] 之前有 i1*u2+i2 個元素,

(b)

A[i1,i2] 的左側, 有 i2 個行, 共 i2*u1 個元素;

A[i1,i2] 所在的這一行, A[i1,i2] 的上方有 i1 個元素;

因此 A[i1,i2] 之前有 i2*u1+i1 個元素,

(c)

A[i1,i2,i3] 的上方, 有 i1 個面, 共 i1*u2*u3 個元素;

A[i1,i2,i3] 所在的這一面, A[i1,i2,i3] 的左側有 i2*u3 個元素;

A[i1,i2,i3] 所在的這一面的這一深度, A[i1,i2,i3] 的前方有 i3 個元素;

因此 A[i1,i2,i3] 之前共有 i1*u2*u3+i2*u3+i3 個元素.

(d)

A 是由深度的從前往後, 一面一面的存, 每一面是按以行為主的方式:

A[i1,i2,i3] 的前方, 有 i3 個面, 共 i3*u1*u2 個元素;

A[i1,i2,i3] 所在的這一面, A[i1,i2,i3] 的左側有 i2*u1 個元素;

A[i1,i2,i3] 所在的這一面的這一行, A[i1,i2,i3] 的上方有 i1 個元素;

因此 A[i1,i2,i3] 之前共有 i3*u1*u2+i2*u1+i1 個元素.