【发布时间】:2016-04-10 02:17:06
【问题描述】:
/** * 初始化二维矩阵(代替构造函数) * 行和列都必须大于零。 * @param rows 整数指定矩阵的高度,必须> 0。 * @param cols 指定矩阵宽度的整数必须 > 0。 * @return 布尔值,如果输入可接受,则为 true,否则为 false。 */
public boolean init(int rows, int cols)
{
matrix = new LinkedList<LinkedList<Integer>>();
if(this.rows < 0 || this.cols < 0)
return false;
if(this.rows > 0 && this.cols > 0)
for(int i = 0; i < rows; i++)
matrix.add(new LinkedList<Integer>());
for(int j = 0; j < cols; j++)
matrix.get(cols).add(j);
return true;
}
我正在尝试使用链表的链表初始化此矩阵,但我被卡住了。
【问题讨论】:
标签: java linked-list