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!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started