matrix.c fertiggestellt
This commit is contained in:
parent
2ea8e29d28
commit
f34adaac30
36
matrix.c
36
matrix.c
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user