Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# linking problems with 2d matrix LL

Andrew Hodel
Greenhorn
Posts: 10
hi all im still in the beginning stages of learning programming and i have a project to represent a 2d matrix with a linked list so far this is what i have:

I know that it is at least going through the whole populate method and i know the list is not linked properly because my toString method is a kind of test for it.
I just dont see where my code fails

my toString outputs
0 1 2 3 4 5 6
1 2 3 4 5 6 7
3 4 5 6 7 8
5 6 7 8 9
7 8 9 10
9 10 11
11 12

Happy Coding

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15571
46
Andrew Hodel wrote:I just dont see where my code fails

Why do you think it fails? Don't expect someone else to automatically know what your code is supposed to do. Explain what you expected, and how the actual output differs from what you expected.

Andrew Hodel
Greenhorn
Posts: 10
..Ok, the matrix indexing starts at 0,0(row, column) for the top left element and the key value for the node is initiated to row+column so the 7-by-7 matrix should output
0 1 2 3 4 5 6
1 2 3 4 5 6 7
2 3 4 5 6 7 8
3 4 5 6 7 8 9
4 5 6 7 8 9 10
5 6 7 8 9 10 11
6 7 8 9 10 11 12
All nodes have a left and a down pointer except, column 6 has left pointers of null, and row 6 has down pointers of null.
The way i think about doing this is by populating the list for row 0 then keeping a pointer to the "leftMost" element in the row, populate the list for row 1 while creating the correct pointers for the row above the current row. However this is proving much more difficult in practice than conceptually.

Andrew Hodel
Greenhorn
Posts: 10
Sorry if anybody was working on a solution but i fixed the problem.. i was make things null and trying to use them to point to things, doesnt work out that well
happy coding