diff --git a/LibAutomaton/CellElement.c b/LibAutomaton/CellElement.c index 6dc9f88..165425f 100644 --- a/LibAutomaton/CellElement.c +++ b/LibAutomaton/CellElement.c @@ -127,6 +127,9 @@ void recursivePrint(cellElement * tree){ } void FreeCellElement(cellElement* element) { + + printf("---FreeCellElement---\n"); + if (element != NULL){ free(element); } diff --git a/LibAutomaton/matrix.c b/LibAutomaton/matrix.c index 6a584aa..3b4477a 100644 --- a/LibAutomaton/matrix.c +++ b/LibAutomaton/matrix.c @@ -30,9 +30,10 @@ Matrix CreateMatrix(){ return matrix; } -void SetMatrixDim(Matrix matrix,int nbCols,int nbRows){ +Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows){ matrix.colCount = nbCols; matrix.rowCount = nbRows; + return matrix; } bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ @@ -42,7 +43,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ cellElement * elem = NULL; cellElement * tmp = NULL; - if (matrix.colCount < ColPos || matrix.rowCount < RowPos){ + if (matrix.colCount <= ColPos || matrix.rowCount <= RowPos ){ return ERROR; } elem = CreateCellElem(); @@ -61,10 +62,10 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ while (tmp->nextCol != NULL && tmp->nextCol->colIndex < ColPos){ tmp=tmp->nextCol; } - if (tmp->nextCol->colIndex > ColPos){ + if (tmp->nextCol == NULL || tmp->nextCol->colIndex > ColPos){ elem->nextCol = tmp->nextCol; tmp->nextCol = elem; - }else if (tmp->colIndex == ColPos){ + }else { error ++; } } @@ -87,10 +88,10 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ while (tmp->nextRow != NULL && tmp->nextRow->rowIndex < RowPos){ tmp=tmp->nextRow; } - if (tmp->nextRow->rowIndex > RowPos){ + if (tmp->nextRow == NULL || tmp->nextRow->rowIndex > RowPos){ elem->nextRow = tmp->nextRow; tmp->nextRow = elem; - }else if (tmp->rowIndex == RowPos){ + }else { error ++; } } @@ -120,7 +121,7 @@ cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos){ } elem = Row->data; - while (elem->colIndex != ColPos && elem != NULL){ + while (elem != NULL && elem->colIndex != ColPos){ elem = elem->nextCol; } @@ -198,7 +199,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){ } bool GetCellValue(Matrix matrix, int ColPos, int RowPos){ - if (matrix.colCount < ColPos || matrix.rowCount < RowPos){ + if (matrix.colCount <= ColPos || matrix.rowCount <= RowPos){ return ERROR; } @@ -218,8 +219,31 @@ bool SetCellValue(Matrix matrix, int ColPos, int RowPos,bool value){ return false; } } - } -/* todos: -*print matrice -*/ \ No newline at end of file + +void BasicPrintMatrix(Matrix matrix){ +/* Non optimisé : debug fx */ + int i = 0; + int j = 0; + + printf("\n---PRINT MATRIX---\n"); + + for (i=0;inextRow,1,2); - - AddNextCol(tree); - SetPositionIndex(tree->nextCol,1,3); - - SetNextRow(tree->nextCol,tree->nextRow); - - recursivePrint(tree); - - - removeNextRow(tree); - removeNextCol(tree); - - recursivePrint(tree); -*/ + SetCellValue(matrix,0,0,false); + SetCellValue(matrix,0,0,false); + BasicPrintMatrix(matrix); return 0; }