一维数组与二维数组的转换.docx
一维数组与二维数组的转换关键:下标的计算 一维->二维 一个n个元素的一维数组,转换为r行c列的二维数组 对于一维数组中任意一个元素的下标i(0 <= i < n) 其对应的二维数组下标为 (i / c, i % c), 显然, 只与列数c有关,而与行数r无关 code like this int a = new intn;int, b = new intr, c;for (int i = 0; i < n; i+) bi / c, i % c = ai; also can write like this for (int i = 0; i < r; i+) for (int j = 0; j < c; j+) bi, j = ai * c + j; 二维->一维 int, a = new intr, c;int b = new intr * c;for(int i = 0; i < b.Length; i+) bi = ai / c, i % c;