Please Help!!

Write a program which will compress a sparse matrix using an orthogonal list structure.

Your program is to read data from a text file "ass2.dat" (available via the web) in the following format:

Alpha x y z.

E.g.
A 2 3 123 Adds 123 to matrix location 2,3. or M[2,3]=123
R 2 3 Prints the value of matrix location 2,3. or z = M[2,3]
Q Quit


When an A or Add is read your program should perform the following:

If the value, or z component is non zero then this value is added into the data structure. Row and column header nodes are added accordingly.
If the value, or z component is non zero and a non zero entry already exists. Then the data value for the given index is replaced by z.
If the value z is 0, and no node exists for index x, y, then the command is ignored.
If the value z is 0 and a location with index M[x, y] is non zero, then this node is removed from the data structure. If this causes a row or column to become empty then the header(s) for these are also removed. Similar to a delete.
A R command will simply print the value of location M[x, y] to the screen. The following format is suggested:
M[x, y] = z
In addition, write a print method which will dump out the matrix in row major order including all header nodes and zero values. This method should be run after the Q or quit has been read. This method will also make debugging much easier. Because the header nodes contain important information in the index fields be sure to print these out as well. Suggest the following format where each node is represented as shown below:
[x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z]

[x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z]

[x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z]

[x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z]

[x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z] [x, y, z]

etc.

"ass2.dat" is

A 2 2 5
R 2 2
A 2 3 6
A 2 4 7
A 7 1 2
A 8 3 6
A 5 4 6
A 9 9 1
A 8 3 5
R 8 3
A 8 3 2
R 8 3
A 3 4 0
A 2 3 0
R 2 3
R 5 4
R 7 1
A 2 4 0
A 5 4 0
R 5 4
A 8 1 3
A 8 2 4
A 8 3 5
A 7 1 2
A 7 2 3
A 9 2 4
R 8 3
A 7 1 0
A 7 2 0
Q



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories