1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-29 15:04:14 +00:00

fini freematrix :)

This commit is contained in:
Naej 2016-12-26 00:06:54 +01:00
parent f30e968e0a
commit 22b653db67
4 changed files with 63 additions and 4 deletions

View File

@ -136,3 +136,4 @@ void FreeCellElement(cellElement* element) {
}
element = NULL;
}

View File

@ -176,11 +176,11 @@ int DeleteListContent(List *list){
while (current != NULL){
toDelete = current;
current = current->next;
/*
if (toDelete->data != NULL){
FreeCellElement(toDelete->data);
}
*/
free(toDelete);
}
list->head = NULL;

View File

@ -157,7 +157,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
tmp = tmp->nextCol;
}
if (tmp->nextCol == NULL){
return -3; /* WTF ?? */
return -3; /* should never happend */
} else {
tmp->nextCol = elem->nextCol;
}
@ -184,7 +184,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
tmp = tmp->nextRow;
}
if (tmp->nextRow == NULL){
return -4; /* WTF ?? */
return -4; /* should never happend */
} else {
tmp->nextRow = elem->nextRow;
}
@ -248,15 +248,70 @@ void BasicPrintMatrix(Matrix matrix){
printf("---END OF MATRIX---\n\n");
}
bool RecursiveFreeCol(Matrix matrix, cellElement * elem){
cellElement * tmp = NULL;
ListElement * Row = NULL;
if (elem == NULL){
return ERROR;
}
if (elem->nextRow != NULL){
RecursiveFreeCol(matrix,elem->nextRow);
}
if (elem->nextRow == NULL){
Row = GetElementPos(matrix.rows,elem->rowIndex);
if (Row == NULL || Row->data == NULL ){
return ERROR; /*should never happend*/
}
if (Row->data->colIndex == elem->colIndex){
Row->data = NULL;
} else {
tmp = Row->data;
while (tmp->nextCol != NULL && tmp->nextCol != elem){
tmp = tmp->nextCol;
}
if (tmp->nextCol == NULL){
return ERROR; /* should never happend */
} else {
tmp->nextCol = elem->nextCol;
}
}
FreeCellElement(elem);
return true;
}
return false; /* should never happend */
}
Matrix freeMatrix(Matrix matrix){
ListElement * current = NULL;
matrix.colCount = 0;
matrix.rowCount = 0;
/*il faut free les cellElements car FreeList ne peut pas le faire*/
if (matrix.cols != NULL){
current= matrix.cols->head;
while (current != NULL){
RecursiveFreeCol(matrix,current->data);
current = current->next;
}
}
FreeList(matrix.cols);
FreeList(matrix.rows);
return matrix;
}
/* todos :
*finir le freeMatrix
*chasser les bugs

View File

@ -110,7 +110,10 @@ Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows);
void BasicPrintMatrix(Matrix matrix);
bool RecursiveFreeCol(Matrix matrix, cellElement * elem);
Matrix freeMatrix(Matrix matrix);
#endif