#include #include #include "matrix.h" // TODO Matrix-Funktionen implementieren /*Matrix createMatrix(unsigned int rows, unsigned int cols) { Matrix matrix; matrix.rows = rows; matrix.cols = cols; matrix.buffer = NULL; if(rows>0 && cols>0) { matrix.buffer = (MatrixType **)malloc(rows * sizeof(MatrixType *)); // Speicher für Zeiger auf Zeilen if(matrix.buffer == NULL) { matrix.rows = 0; matrix.cols = 0; return matrix; } for(int i=0;i 0 && cols > 0) { matrix.buffer = malloc(rows * cols * sizeof(MatrixType)); if (matrix.buffer == NULL) { return matrix; } matrix.rows = rows; matrix.cols = cols; memset(matrix.buffer, UNDEFINED_MATRIX_VALUE, rows*cols); } return matrix; } void clearMatrix(Matrix *matrix) { free(matrix->buffer); matrix->rows = 0; matrix->cols = 0; matrix->buffer = NULL; free(matrix->buffer); } void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { if(rowIdx<(matrix.rows) && colIdx<(matrix.cols)){ matrix.buffer[matrix.cols*rowIdx + colIdx]=value; } } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { if(rowIdx<(matrix.rows) && colIdx<(matrix.cols)){ return matrix.buffer[matrix.cols*rowIdx + colIdx]; } else{ return UNDEFINED_MATRIX_VALUE; } } Matrix add(const Matrix matrix1, const Matrix matrix2) { Matrix output = {.rows=0, .cols=0, .buffer=NULL}; if(matrix1.rows==matrix2.rows && matrix1.cols==matrix2.cols){ output.rows = matrix1.rows; output.cols = matrix1.cols; for (int i=0;i