matrix.c fertiggestellt

This commit is contained in:
Sven Hofmann 2025-11-28 08:37:59 +01:00
parent 2ea8e29d28
commit f34adaac30

View File

@ -6,19 +6,47 @@
/* Erstellt eine Matrix mit den gegebenen Zeilen und Spalten */
Matrix createMatrix(unsigned int rows, unsigned int cols)
{
Matrix m;
if (rows == 0 || cols == 0)
{
m.rows = 0;
m.cols = 0;
m.buffer = NULL;
return m;
}
m.rows = rows;
m.cols = cols;
m.buffer = (MatrixType *)calloc(rows * cols, sizeof(MatrixType));
return m;
}
/* Löscht eine Matrix */
void clearMatrix(Matrix *matrix)
{
if (matrix != NULL)
{
if (matrix->buffer != NULL)
{
free(matrix->buffer);
matrix->buffer = NULL;
}
matrix->rows = 0;
matrix->cols = 0;
}
}
/* Setzt einen Wert in die Matrix an der gegebenen Stelle */
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{
if (matrix.buffer != NULL)
{
if (rowIdx < matrix.rows && colIdx < matrix.cols)
{
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
}
}
}
/* Ausgeben eines Wertes aus der Matrix
* matrix Die Matrix