Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing 2D into "1D"

 
John Stevens
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just an extension of my last post on Tridiagonal matrix.
I've got for example the following matrix:
1 4 0 0
1 3 5 0
0 3 4 4
0 0 6 6
How do I store only the non-zero numbers in a one dimensional array in this order:
1, 4, 1, 3, 5, 3, 4, 4, 6, 6
???
 
Vinod Venkatasubramanian
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If efficieny is not an issue, you could try using ArrayList to dynamically grow the array.
Basically, traverse the input array and for every element you want inserted into the destination array, use ArrayList.add.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic