Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the linked list sparse matrix class in LLSparseMat.java so that LLMainClass can be executed with MAT argument. -------------------------------------------------------------------------------------------------------------------------------------------------------- //this is the class that needs

Implement the linked list sparse matrix class in LLSparseMat.java so that LLMainClass

can be executed with MAT argument.

--------------------------------------------------------------------------------------------------------------------------------------------------------

//this is the class that needs to be completed

public class LLSparseM implements SparseM {

public LLSparseM(int nr, int nc){ return; }

@Override public int nrows() { // TODO Auto-generated method stub return 0; }

@Override public int ncols() { // TODO Auto-generated method stub return 0; }

@Override public int numElements() { // TODO Auto-generated method stub return 0; }

@Override public int getElement(int ridx, int cidx) { // TODO Auto-generated method stub return 0; }

@Override public void clearElement(int ridx, int cidx) { // TODO Auto-generated method stub

}

@Override public void setElement(int ridx, int cidx, int val) { // TODO Auto-generated method stub

}

@Override public int[] getRowIndices() { // TODO Auto-generated method stub return null; }

@Override public int[] getOneRowColIndices(int ridx) { // TODO Auto-generated method stub return null; }

@Override public int[] getOneRowValues(int ridx) { // TODO Auto-generated method stub return null; }

@Override public SparseM addition(SparseM otherM) { // TODO Auto-generated method stub return null; }

@Override public SparseM subtraction(SparseM otherM) { // TODO Auto-generated method stub return null; }

@Override public SparseM multiplication(SparseM otherM) { // TODO Auto-generated method stub return null; }

}

LLSparseVec.getAllValues().

- NOTE that these methods should all be linear to the number of nonzero rows or

nonzero elements

.image text in transcribedimage text in transcribed

import java.util.Scanner; import java.io.File; public class LLMainClass { public static SparseM ParseMatrix(String file_name) { Scanner SC = null; String tmps; SparseM M = null; try { sc = new Scanner(new File(file_name)); while (sc. hasNext()) { tmps = sc.next(); if(tmps.equals("MATRIX")) { // initialize the matrix int nr = sc.nextInt(); int nc = sc.nextInt(); M = new LLSparseM(nr,nc); }else if(tmps.equals("END")) { // finished, return the matrix sc.close(); return M; }else if(tmps.equals("SET")) { // set an element int ridx = sc.nextInt(); // row index int cidx = sc.nextInt(); // col index int val = sc.nextInt(); // value, M.setElement(ridx, cidx, val); }else if(tmps.equals("CLEAR")) { // clear an element int ridx = sc.nextInt( row index }else if(tmps.equals("CLEAR")) { // clear an element int ridx = sc.nextInt(); // row index int cidx = sc.nextInt(); // col index M.clearElement(ridx, cidx); sc.close(); return M; } catch (Exception e) { | return nul; public static SparseVec ParseVector(String file_name) {, Scanner sc = null; String tmps; Sparsevec V = null; try { sc = new Scanner(new File(file_name)); while (sc. hasNext()) { tmps = sc.next(); if(tmps.equals("VECTOR")) { // initialize the matrix int len = sc.nextInt(); V = new LLSparseVec(len); '}else if(tmps.equals("END")) { // finished, return the matrix sc.close(); return V; 1.1. CIL- import java.util.Scanner; import java.io.File; public class LLMainClass { public static SparseM ParseMatrix(String file_name) { Scanner SC = null; String tmps; SparseM M = null; try { sc = new Scanner(new File(file_name)); while (sc. hasNext()) { tmps = sc.next(); if(tmps.equals("MATRIX")) { // initialize the matrix int nr = sc.nextInt(); int nc = sc.nextInt(); M = new LLSparseM(nr,nc); }else if(tmps.equals("END")) { // finished, return the matrix sc.close(); return M; }else if(tmps.equals("SET")) { // set an element int ridx = sc.nextInt(); // row index int cidx = sc.nextInt(); // col index int val = sc.nextInt(); // value, M.setElement(ridx, cidx, val); }else if(tmps.equals("CLEAR")) { // clear an element int ridx = sc.nextInt( row index }else if(tmps.equals("CLEAR")) { // clear an element int ridx = sc.nextInt(); // row index int cidx = sc.nextInt(); // col index M.clearElement(ridx, cidx); sc.close(); return M; } catch (Exception e) { | return nul; public static SparseVec ParseVector(String file_name) {, Scanner sc = null; String tmps; Sparsevec V = null; try { sc = new Scanner(new File(file_name)); while (sc. hasNext()) { tmps = sc.next(); if(tmps.equals("VECTOR")) { // initialize the matrix int len = sc.nextInt(); V = new LLSparseVec(len); '}else if(tmps.equals("END")) { // finished, return the matrix sc.close(); return V; 1.1. CIL

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions