-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sparse_Matrix.h
38 lines (33 loc) · 884 Bytes
/
Sparse_Matrix.h
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
#ifndef SPARSE_MATRIX_H
#define SPARSE_MATRIX_H
#include "../source/Sparse_Array.cpp"
template <class T>
struct Row_Node
{
int row;
Sparse_Array<T> list;
Row_Node<T> *next{};
Row_Node<T> *prev{};
Row_Node(int r, int c) : row(r), list(c) {}
};
template <class type>
class Sparse_Matrix
{
Row_Node<type> *head{};
Row_Node<type> *tail{};
int length{};
int rows{};
int cols{};
Row_Node<type> *get_row(int row, bool flag);
void link(Row_Node<type> *first, Row_Node<type> *second);
Row_Node<type> *add_node_between_node_and_next(Row_Node<type> *node_before, int row);
public:
Sparse_Matrix(int rows, int cols);
~Sparse_Matrix();
void set_value(type data, int row, int col);
type get_value(int row, int col);
void add(Sparse_Matrix<type> &other);
void print_matrix();
void print_matrix_nonzero();
};
#endif