Added single array matrix

This commit is contained in:
Fabio Salvini
2016-11-13 11:06:05 +01:00
parent 51442687a0
commit df121930ad
3 changed files with 52 additions and 23 deletions

View File

@@ -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;

View File

@@ -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);