Need Java Data Structure Matrix Code Class of Array List of Entry Objects Reviewed and Revised

java , Deque , ADT Hayward, United States
  • 11 years ago

    I need to know if my data structure classes have been properly created to accomplish the following:

    I am trying to represent a matrix as a 1-dimensional array of Lists. Each List will represent one row of the Matrix, but only the non-zero entries will be stored. List elements must store the matrix entries and its column location. For example, the matrix below would have the following representation as an array of Lists.

    • | 0.0 4.0 5.0 |
    • M = | 3.0 0.0 0.0 |
    • | 1.0 0.0 2.0 |

    • 1: (1, 1.0) (3, 2.0)

    • Array of Lists = 2: (1, 3.0)
    • 3: (2, 4.0) (3, 5.0)

    I have created two classes in different ADT files: The Matrix class and the List class. The goal is to create a two dimensional matrix as an array of Lists of Entry Objects. More specifically, the Matrix will be an array of deque linked list of Entry Objects. Only non-zero entries will be stored in the Matrix class. Therefore, the linked list (representing the rows of the matrix) is dynamically created since the entries of the matrix can be entered in any order. Entries are identified by their row, column, and value attributes.

    Matrix.java code: class Matrix { private class Entry { int col; double val;

          // Entry Constructor
          Entry (int c, double v) {
             this.col = c; this.val = v;
          }
    
       }
    }
    

    List.java code: class List { private class Node { Object obj; Node next, prev;

          // Node Constructor
          Node (Object o) { this.obj = o; next = prev = null; }
       }
    
       // List Fields
       private Node front, back, current;
       private int row, length;
    
       // List Constructor
       List(int r)
       {  front = back = current = null;
          this.row = r; this.length = 0;
       }
    }
    

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If Java had true garbage collection, most programs would delete themselves upon execution.” - Robert Sewell