From 8ac27e20c578d0d2469288d212caf22065770003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Mon, 17 Nov 2025 13:46:22 +0100 Subject: [PATCH] Matrix Funktion an Test angepasst --- matrix.c | 26 +++++++++++++------------- matrix.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/matrix.c b/matrix.c index 1ffe1d5..a0e2ccf 100644 --- a/matrix.c +++ b/matrix.c @@ -12,12 +12,12 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) matrix.cols = cols; if (rows == 0 || cols == 0) { - matrix.data = NULL; + matrix.buffer = NULL; return matrix; } - matrix.data = (MatrixType *)malloc(rows * cols * sizeof(MatrixType)); - if (matrix.data == NULL) + matrix.buffer = (MatrixType *)malloc(rows * cols * sizeof(MatrixType)); + if (matrix.buffer == NULL) { matrix.rows = 0; matrix.cols = 0; @@ -28,10 +28,10 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) // Matrix Speicher freigeben void clearMatrix(Matrix *matrix) { - if (matrix->data != NULL) + if (matrix->buffer != NULL) { - free(matrix->data); - matrix->data = NULL; + free(matrix->buffer); + matrix->buffer = NULL; } matrix->rows = 0; matrix->cols = 0; @@ -42,7 +42,7 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned { if (rowIdx < matrix.rows && colIdx < matrix.cols) { - matrix.data[rowIdx * matrix.cols + colIdx] = value; + matrix.buffer[rowIdx * matrix.cols + colIdx] = value; } } @@ -51,7 +51,7 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co { if (rowIdx < matrix.rows && colIdx < matrix.cols) { - return matrix.data[rowIdx * matrix.cols + colIdx]; + return matrix.buffer[rowIdx * matrix.cols + colIdx]; } return 0; // Fallback } @@ -61,17 +61,17 @@ Matrix add(const Matrix m1, const Matrix m2) { if (m1.rows != m2.rows || m1.cols != m2.cols) { - return createMatrix(0, 0); // Dimension passt nicht + return createMatrix(0, 0); // Falls Matrix-Dimensionen nicht passen } Matrix result = createMatrix(m1.rows, m1.cols); - if (result.data == NULL) return result; + if (result.buffer == NULL) return result; for (unsigned int r = 0; r < m1.rows; r++) { for (unsigned int c = 0; c < m1.cols; c++) { - result.data[r * m1.cols + c] = + result.buffer[r * m1.cols + c] = getMatrixAt(m1, r, c) + getMatrixAt(m2, r, c); } } @@ -87,7 +87,7 @@ Matrix multiply(const Matrix m1, const Matrix m2) } Matrix result = createMatrix(m1.rows, m2.cols); - if (result.data == NULL) return result; + if (result.buffer == NULL) return result; for (unsigned int r = 0; r < m1.rows; r++) { @@ -98,7 +98,7 @@ Matrix multiply(const Matrix m1, const Matrix m2) { sum += getMatrixAt(m1, r, k) * getMatrixAt(m2, k, c); } - result.data[r * m2.cols + c] = sum; + result.buffer[r * m2.cols + c] = sum; } } diff --git a/matrix.h b/matrix.h index 2beabc1..c85e38c 100644 --- a/matrix.h +++ b/matrix.h @@ -10,7 +10,7 @@ typedef struct { unsigned int rows; unsigned int cols; - MatrixType *data; + MatrixType *buffer; } Matrix;