1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-05 08:18:03 +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{
true = 1,
false = 0
false = 0,
ERROR = -1
} bool;

View File

@ -30,13 +30,21 @@ Matrix CreateMatrix(){
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 * Col = NULL;
int error = 0;
cellElement * elem = NULL;
cellElement * tmp = NULL;
if (matrix.colCount < ColPos || matrix.rowCount < RowPos){
return ERROR;
}
elem = CreateCellElem();
SetPositionIndex(elem,ColPos,RowPos);
@ -95,7 +103,11 @@ void CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){
if (error != 0){
free(elem);
return true;
}else{
return false;
}
}
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){
if (matrix.colCount < ColPos || matrix.rowCount < RowPos){
return ERROR;
}
if (FindMatrixElem(matrix,ColPos,RowPos) == NULL){
return false;
}
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){
CreateMatrixElem(matrix,ColPos,RowPos);
return CreateMatrixElem(matrix,ColPos,RowPos);
}else{
SupprMatrixElem(matrix,ColPos,RowPos);
if ( SupprMatrixElem(matrix,ColPos,RowPos) >= 0 ){
return true;
}else{
return false;
}
}
}
/* todos:
*gerer bornes matrice
*print matrice
*/

View File

@ -67,12 +67,15 @@ cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos);
*@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);
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);
void SetMatrixDim(Matrix matrix,int nbCols,int nbRows);
#endif