-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedmatrix.h
More file actions
60 lines (53 loc) · 2 KB
/
Copy pathlinkedmatrix.h
File metadata and controls
60 lines (53 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//============================================================================
// Name : DS Assignment#1
// Author : Ashmit Mukherjee
// Version : 1.0
// Date Created : 14-02-2023
// Date Modified:
// Description : Linked List-based Matrix class for an optimized structure
//============================================================================
#ifndef LINKEDMATRIX_H //include guards
#define LINKEDMATRIX_H
#include<cstdlib>
#include<iomanip>
#include<iostream>
using namespace std;
class Node
{
private:
int row; //the row index
int column; //the column index
int value; //the value of the element
Node* next; //pointer to the next node within the same row
Node* down; //pointer to the next node within the same column
public:
friend class LinkedMatrix;
friend class MatComp;
Node(int row, int column, int value) : row(row), column(column), value(value), next(NULL), down(NULL)
{}
//add any other necessary code here
};
//=============================================================================
class LinkedMatrix
{
private:
int numRows; //the number of rows
int numCols; //the number of columns
int numNonZeroElements;
Node** rowArray;
Node** colArray;
public:
friend class MatComp;
LinkedMatrix();
void create(int numRows, int numCols); // creates an empty matrix given the provided dimensions
int getNumRows() const; // returns the total number of rows
int getNumCols() const; // returns the total number of columns
void display() const; // display the matrix dimensions, number of non-zero members, and the non-zero members' cardinalities+values
void display2D() const; // display the matrix dimensions, number of non-zero members, and the non-zero members' cardinalities+values
void insertElement(int Row_Indx, int Col_Indx, int value);
void removeElement(int Row_Indx, int Col_Indx);
int getValue(int Row_Indx, int Col_Indx) const;
~LinkedMatrix(); // destructor to properly delete the matrix and deallocate all nodes
//add any other necessary code here
};
#endif