diff --git a/LibAutomaton/CellElement.c b/LibAutomaton/CellElement.c index 96fc5c8..e0fbfa1 100644 --- a/LibAutomaton/CellElement.c +++ b/LibAutomaton/CellElement.c @@ -136,3 +136,4 @@ void FreeCellElement(cellElement* element) { } element = NULL; } + diff --git a/LibAutomaton/list.c b/LibAutomaton/list.c index 8b8a7e1..e44b428 100644 --- a/LibAutomaton/list.c +++ b/LibAutomaton/list.c @@ -176,11 +176,11 @@ int DeleteListContent(List *list){ while (current != NULL){ toDelete = current; current = current->next; - +/* if (toDelete->data != NULL){ FreeCellElement(toDelete->data); } - +*/ free(toDelete); } list->head = NULL; diff --git a/LibAutomaton/matrix.c b/LibAutomaton/matrix.c index a0b9154..620ec8f 100644 --- a/LibAutomaton/matrix.c +++ b/LibAutomaton/matrix.c @@ -157,7 +157,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){ tmp = tmp->nextCol; } if (tmp->nextCol == NULL){ - return -3; /* WTF ?? */ + return -3; /* should never happend */ } else { tmp->nextCol = elem->nextCol; } @@ -184,7 +184,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){ tmp = tmp->nextRow; } if (tmp->nextRow == NULL){ - return -4; /* WTF ?? */ + return -4; /* should never happend */ } else { tmp->nextRow = elem->nextRow; } @@ -248,15 +248,70 @@ void BasicPrintMatrix(Matrix matrix){ printf("---END OF MATRIX---\n\n"); } +bool RecursiveFreeCol(Matrix matrix, cellElement * elem){ + cellElement * tmp = NULL; + ListElement * Row = NULL; + + if (elem == NULL){ + return ERROR; + } + + if (elem->nextRow != NULL){ + RecursiveFreeCol(matrix,elem->nextRow); + } + + if (elem->nextRow == NULL){ + + Row = GetElementPos(matrix.rows,elem->rowIndex); + + if (Row == NULL || Row->data == NULL ){ + return ERROR; /*should never happend*/ + } + + if (Row->data->colIndex == elem->colIndex){ + Row->data = NULL; + } else { + tmp = Row->data; + while (tmp->nextCol != NULL && tmp->nextCol != elem){ + tmp = tmp->nextCol; + } + if (tmp->nextCol == NULL){ + return ERROR; /* should never happend */ + } else { + tmp->nextCol = elem->nextCol; + } + + } + + FreeCellElement(elem); + return true; + } + + return false; /* should never happend */ +} + + + Matrix freeMatrix(Matrix matrix){ + ListElement * current = NULL; + 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){ + RecursiveFreeCol(matrix,current->data); + current = current->next; + } + } FreeList(matrix.cols); FreeList(matrix.rows); return matrix; } + + /* todos : *finir le freeMatrix *chasser les bugs diff --git a/LibAutomaton/matrix.h b/LibAutomaton/matrix.h index 92aca29..b1cbef5 100644 --- a/LibAutomaton/matrix.h +++ b/LibAutomaton/matrix.h @@ -110,7 +110,10 @@ Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows); void BasicPrintMatrix(Matrix matrix); +bool RecursiveFreeCol(Matrix matrix, cellElement * elem); + Matrix freeMatrix(Matrix matrix); + #endif