Reference no: EM132808577
Question 1: Write code to complete a program (download it from Stream) that reads in two sparse matrices from *.txt files and stores them as linked lists (dynamic memory). Use either the c or cpp start-up code available on Stream. The prototype reads text files in a specific format, with the first lines indicating the number of rows and columns (see example on Stream).
Write the function that adds the two matrices together and produce a result matrix. The result matrix must also be stored as a linked list. We are assuming that the matrices are too large to fit into memory as arrays, thus all calculations must be carried out with the matrices stored in their linked list format.
Write a display function that shows all three matrices in the usual matrix format.
Write a display function that shows all three linked lists in order of elements.
Note 1: The programs should read the matrices from the *.txt files, NOT from keyboard. Use the sample codes provided on Stream. Use either the C or the C++ style (both files provided on Stream).
Note 2: Make sure that values of zero are not nodes in the linked list (after all, that's the point in implementing the sparse matrix code!).
Note 3: The output must be in this format. This example has 4x4 matrices:
Matrix 1: 1 2 3 4 5
0 1 0 0 0 0 2 0 0 3 0 4 0 0 0 5 Matrix 2: 1 1 2 3 4 10 3 3
1 1 2 0 0 0 3 0 0 4 0 10 0 0 3 3 Matrix Result: 1 2 2 5 7 14 3 8
1 2 2 0 0 0 5 0 0 7 0 14 0 0 3 8
If the matrix is all zeros, it should be printed like this, indicating that the corresponding linked-list is empty:
Matrix 2:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
Attachment:- GivenCode.rar