This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

linking problems with 2d matrix LL

 
Andrew Hodel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
..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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic