1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-05 10:58:02 +00:00

ajout gestion bornes matrice

This commit is contained in:
Naej 2016-12-24 13:53:04 +01:00
parent 0a6c7524e0
commit 8e72e57179
3 changed files with 31 additions and 8 deletions

View File

@ -9,7 +9,8 @@
typedef enum Bool{ typedef enum Bool{
true = 1, true = 1,
false = 0 false = 0,
ERROR = -1
} bool; } bool;

View File

@ -30,13 +30,21 @@ Matrix CreateMatrix(){
return matrix; return matrix;
} }
void CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ void SetMatrixDim(Matrix matrix,int nbCols,int nbRows){
matrix.colCount = nbCols;
matrix.rowCount = nbRows;
}
bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){
ListElement * Row = NULL; ListElement * Row = NULL;
ListElement * Col = NULL; ListElement * Col = NULL;
int error = 0; int error = 0;
cellElement * elem = NULL; cellElement * elem = NULL;
cellElement * tmp = NULL; cellElement * tmp = NULL;
if (matrix.colCount < ColPos || matrix.rowCount < RowPos){
return ERROR;
}
elem = CreateCellElem(); elem = CreateCellElem();
SetPositionIndex(elem,ColPos,RowPos); SetPositionIndex(elem,ColPos,RowPos);
@ -95,7 +103,11 @@ void CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){
if (error != 0){ if (error != 0){
free(elem); free(elem);
return true;
}else{
return false;
} }
} }
cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos){ cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos){
@ -186,21 +198,28 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
} }
bool GetCellValue(Matrix matrix, int ColPos, int RowPos){ bool GetCellValue(Matrix matrix, int ColPos, int RowPos){
if (matrix.colCount < ColPos || matrix.rowCount < RowPos){
return ERROR;
}
if (FindMatrixElem(matrix,ColPos,RowPos) == NULL){ if (FindMatrixElem(matrix,ColPos,RowPos) == NULL){
return false; return false;
} }
return true; return true;
} }
void SetCellValue(Matrix matrix, int ColPos, int RowPos,bool value){ bool SetCellValue(Matrix matrix, int ColPos, int RowPos,bool value){
if (value == true){ if (value == true){
CreateMatrixElem(matrix,ColPos,RowPos); return CreateMatrixElem(matrix,ColPos,RowPos);
}else{ }else{
SupprMatrixElem(matrix,ColPos,RowPos); if ( SupprMatrixElem(matrix,ColPos,RowPos) >= 0 ){
return true;
}else{
return false;
}
} }
} }
/* todos: /* todos:
*gerer bornes matrice
*print matrice *print matrice
*/ */

View File

@ -67,12 +67,15 @@ cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos);
*@return void *@return void
* *
*/ */
void CreateMatrixElem(Matrix matrix, int ColPos, int RowPos); bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos);
int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos); int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos);
void SetCellValue(Matrix matrix, int ColPos, int RowPos,bool value); bool SetCellValue(Matrix matrix, int ColPos, int RowPos, bool value);
bool GetCellValue(Matrix matrix, int ColPos, int RowPos); bool GetCellValue(Matrix matrix, int ColPos, int RowPos);
void SetMatrixDim(Matrix matrix,int nbCols,int nbRows);
#endif #endif