Question: Use m singly linked lists to represent an m x n sparse matrix A, i.e. the values in a small portion of cells are non-zero,

Use m singly linked lists to represent an m x n sparse matrix A, i.e. the values in a small portion of cells are non-zero, where m and n can be quite large. Hence, array implementation will not be ACCEPTED. Write a program in Java to construct A. In this program, the input, i.e. m and n, should be inputted by a user. Moreover, the program needs to provide the following five functions:

1. Get the value at A(i, j) as given i and j; 2. Insert the value at A(i, j) as given i and j; 3. Delete the value at A(i, j) as given i and j; 4. Print the values at the jth column of A as given j; 5. Print the values at the ith row of A as given i; where 1 i m and 1 j n.

Sample input and output:

Sparse Matrix setup No. of rows: 5 No. of columns: 4

5 x 4 sparse matrix is created.

> insert 10 3 2 Inserted 10 to cell(3,2).

> insert 20 2 3 Inserted 20 to cell(2,3).

> insert 30 1 1 Inserted 30 to cell(1,1).

> insert 40 2 2 Inserted 40 to cell(2,2).

> row 2 0 40 20 0

> col 2

0 40 10 0 0

> delete 2 3

delete cell(2,3).

> get 2 3 The value of cell(2,3) is 0.

> get 3 2 The value of cell(3,2) is 10.

> stop Thank you for using this program!

Please don't just copy the answer from the question that I asked.

getRow() and getCol() are needed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!