From 0ef7a0b50931528fa891f9b86256606b526199f7 Mon Sep 17 00:00:00 2001 From: Naej Date: Mon, 26 Dec 2016 20:13:35 +0100 Subject: [PATCH 1/2] =?UTF-8?q?ajout=C3=A9=20le=20sum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LibAutomaton/matrix.c | 28 ++++++++++++++++++++++++++-- LibAutomaton/matrix.h | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/LibAutomaton/matrix.c b/LibAutomaton/matrix.c index dad465a..1a5e554 100644 --- a/LibAutomaton/matrix.c +++ b/LibAutomaton/matrix.c @@ -297,7 +297,7 @@ Matrix freeMatrix(Matrix matrix){ matrix.colCount = 0; matrix.rowCount = 0; - /*il faut free les cellElements car FreeList ne peut pas le faire*/ + if (matrix.cols != NULL){ current= matrix.cols->head; while (current != NULL){ @@ -310,9 +310,33 @@ Matrix freeMatrix(Matrix matrix){ return matrix; } +Matrix sumMatrix(Matrix matrix1,Matrix matrix2){ + Matrix SumMatrix = CreateMatrix(); + int i =0; + int j = 0; + + if (matrix1.colCount == matrix2.colCount && matrix1.rowCount == matrix2.rowCount){ + SumMatrix = SetMatrixDim(SumMatrix,matrix2.colCount,matrix1.rowCount); + for (i=0;i Date: Tue, 27 Dec 2016 22:26:06 +0100 Subject: [PATCH 2/2] =?UTF-8?q?corrig=C3=A9=20free?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LibAutomaton/matrix.c | 22 +++++++++++++--------- main.c | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/LibAutomaton/matrix.c b/LibAutomaton/matrix.c index ed0b051..f49f7c4 100644 --- a/LibAutomaton/matrix.c +++ b/LibAutomaton/matrix.c @@ -83,7 +83,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ } else if (Col->data->rowIndex > RowPos){ elem->nextRow = Col->data; Col->data = elem; - } else { + } else {NMWZxm5uQt tmp = Col->data; while (tmp->nextRow != NULL && tmp->nextRow->rowIndex < RowPos){ tmp=tmp->nextRow; @@ -295,18 +295,22 @@ bool RecursiveFreeCol(Matrix matrix, cellElement * elem){ Matrix freeMatrix(Matrix matrix){ - ListElement * current = NULL; + int i = 0; + int j = 0; + + printf("\n---FREE MATRIX---\n"); - matrix.colCount = 0; - matrix.rowCount = 0; + for (i=0;ihead; - while (current != NULL){ - RecursiveFreeCol(matrix,current->data); - current = current->next; } + } + + printf("---END OF MATRIX---\n\n"); FreeList(matrix.cols); FreeList(matrix.rows); return matrix; diff --git a/main.c b/main.c index 32c6445..5652bfb 100644 --- a/main.c +++ b/main.c @@ -34,6 +34,9 @@ int main(int argc, char **argv){ freeMatrix(m2); m2 = rowSequenceOnMatrix(matrix, AND); BasicPrintMatrix(m2); + + /*sumMatrix(matrix,m2);*/ + freeMatrix(m2); freeMatrix(matrix);