1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-26 04:24:14 +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:
Naej 2016-12-24 15:18:19 +01:00
parent 8e72e57179
commit db8322f504
4 changed files with 51 additions and 40 deletions

View File

@ -127,6 +127,9 @@ void recursivePrint(cellElement * tree){
}
void FreeCellElement(cellElement* element) {
printf("---FreeCellElement---\n");
if (element != NULL){
free(element);
}

View File

@ -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");
}

View File

@ -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

36
main.c
View File

@ -12,38 +12,20 @@
int main(int argc, char **argv){
Matrix matrix = CreateMatrix();
int Rule = 170;
int Rule = 256;
int N = 1;
applyRules(matrix,Rule,N);
/*
Matrix matrix;
cellElement * tree = NULL;
List * cols = NULL;
List * rows = NULL;
matrix = SetMatrixDim(matrix,1,2);
cols = CreateList();
rows = CreateList();
BasicPrintMatrix(matrix);
SetCellValue(matrix,0,0,true);
SetCellValue(matrix,0,0,true);
BasicPrintMatrix(matrix);
tree = CreateCellElem();
SetPositionIndex(tree,1,1);
AddNextRow(tree);
SetPositionIndex(tree->nextRow,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;
}