what's the best suitable data structure to use in C for sparse dynamic matrix. I know about the Yale format but it's for static matrices. I need to be able to add rows column and values in it.
In general, an array of linked lists. If most of the operations are row-based, each list represent a row, otherwise, each list represent a column. You can get more info here
typedef struct matrix {
node** rowList; // rowList is a pointer to the array of rows
node** columnList; // column list is a pointer to the array of columns.
int rows, columns; // store the number of rows and columns of the matrix
} matrix
typedef struct node {
int row, column,
double value;
struct node* rowPtr;
struct node* colPtr;
} node;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With