Forums Register Login

linking problems with 2d matrix LL

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
..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.
+Pie Number of slices to send: Send
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
My, my, aren't you a big fella. Here, have a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 878 times.
Similar Threads
null pointer exception in Game Of Life
Generate random strings
oxo game
tic-tac-toe board
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:34:39.