Added single array matrix
This commit is contained in:
@@ -1,6 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* Create a matrix stored in a single array.
|
||||
*/
|
||||
double *create_sa_matrix(int rows, int cols) {
|
||||
double *x;
|
||||
|
||||
x = (double *) malloc(rows * cols * sizeof(double));
|
||||
return x;
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy a single array matrix.
|
||||
*/
|
||||
void destroy_sa_matrix(double *x) {
|
||||
free(x);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the index for the single array matrix
|
||||
* that correspond to the given row and column.
|
||||
*/
|
||||
int sa_index(int cols, int r, int c) {
|
||||
return r * cols + c;
|
||||
}
|
||||
|
||||
double **create_matrix(int rows, int cols) {
|
||||
int i;
|
||||
|
||||
@@ -16,7 +16,12 @@ typedef struct borders {
|
||||
double west;
|
||||
} borders;
|
||||
|
||||
|
||||
double *create_sa_matrix(int rows, int cols);
|
||||
void destroy_sa_matrix(double *x);
|
||||
int sa_index(int cols, int r, int c);
|
||||
|
||||
double **create_matrix(int rows, int cols);
|
||||
void destroy_matrix(double **x, int rows);
|
||||
|
||||
void print_matrix(double **x, int rows, int cols);
|
||||
void destroy_matrix(double **x, int rows);
|
||||
|
||||
Reference in New Issue
Block a user