mirror of
https://gitlab.com/klmp200/LO27.git
synced 2025-07-11 22:49:23 +00:00
ajouté print et corrigé plein de fautes, reste une fuite mémoire : on peut créer deux fois la meme case
This commit is contained in:
@ -127,6 +127,9 @@ void recursivePrint(cellElement * tree){
|
||||
}
|
||||
|
||||
void FreeCellElement(cellElement* element) {
|
||||
|
||||
printf("---FreeCellElement---\n");
|
||||
|
||||
if (element != NULL){
|
||||
free(element);
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
||||
void BasicPrintMatrix(Matrix matrix){
|
||||
/* Non optimisé : debug fx */
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
printf("\n---PRINT MATRIX---\n");
|
||||
|
||||
for (i=0;i<matrix.colCount;i++){
|
||||
printf("| ");
|
||||
for (j=0;j<matrix.rowCount;j++){
|
||||
|
||||
if (GetCellValue(matrix,i,j) == true){
|
||||
printf("1 ");
|
||||
}else if (GetCellValue(matrix,i,j) == false){
|
||||
printf("0 ");
|
||||
}else{
|
||||
printf("X "); /* error out of bounds, should never happend*/
|
||||
}
|
||||
|
||||
}
|
||||
printf("|\n");
|
||||
|
||||
}
|
||||
|
||||
printf("---END OF MATRIX---\n\n");
|
||||
}
|
@ -75,7 +75,9 @@ bool SetCellValue(Matrix matrix, int ColPos, int RowPos, bool value);
|
||||
|
||||
bool GetCellValue(Matrix matrix, int ColPos, int RowPos);
|
||||
|
||||
void SetMatrixDim(Matrix matrix,int nbCols,int nbRows);
|
||||
Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows);
|
||||
|
||||
void BasicPrintMatrix(Matrix matrix);
|
||||
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user