Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Aside from the syntax issues, it seems strange to me to use an array and a linked list to represent a matrix. To be able to access arbitrary cells of the matrix, you would probably want an actual array or at least an <code>ArrayList</code> to hold the rows, as <code>LinkedList</code> must traverse the whole list from the first element to any particular element, an <code>O(n)</code> operation, as opposed to the much quicker <code>O(1)</code> with <code>ArrayList</code> or an actual array.</p> <p>Since you mentioned this matrix is sparse, though, perhaps a better way to store the data is as a map of maps, where a key in the first map represents a row index, and its value is a row map whose keys are a column index, with the value being your IntegerNode class. Thus:</p> <pre><code>private Map&lt;Integer, Map&lt;Integer, IntegerNode&gt;&gt; myMatrix = new HashMap&lt;Integer, Map&lt;Integer, IntegerNode&gt;&gt;(); // access a matrix cell: int rowIdx = 100; int colIdx = 30; Map&lt;Integer, IntegerNode&gt; row = myMatrix.get(rowIdx); // if null, create and add to matrix IntegerNode node = row.get(colIdx); // possibly null </code></pre> <p>If you need to be able to traverse the matrix row by row, you can make the row map type a <code>TreeMap</code>, and same for traversing the columns in index order, but if you don't need those cases, <code>HashMap</code> is quicker than <code>TreeMap</code>. Helper methods to get and set an arbitrary cell, handling unset null values, would be useful, of course.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload