mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-05 10:48:03 +00:00
fini freematrix :)
This commit is contained in:
parent
f30e968e0a
commit
22b653db67
@ -136,3 +136,4 @@ void FreeCellElement(cellElement* element) {
|
|||||||
}
|
}
|
||||||
element = NULL;
|
element = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,11 +176,11 @@ int DeleteListContent(List *list){
|
|||||||
while (current != NULL){
|
while (current != NULL){
|
||||||
toDelete = current;
|
toDelete = current;
|
||||||
current = current->next;
|
current = current->next;
|
||||||
|
/*
|
||||||
if (toDelete->data != NULL){
|
if (toDelete->data != NULL){
|
||||||
FreeCellElement(toDelete->data);
|
FreeCellElement(toDelete->data);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
free(toDelete);
|
free(toDelete);
|
||||||
}
|
}
|
||||||
list->head = NULL;
|
list->head = NULL;
|
||||||
|
@ -157,7 +157,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
|||||||
tmp = tmp->nextCol;
|
tmp = tmp->nextCol;
|
||||||
}
|
}
|
||||||
if (tmp->nextCol == NULL){
|
if (tmp->nextCol == NULL){
|
||||||
return -3; /* WTF ?? */
|
return -3; /* should never happend */
|
||||||
} else {
|
} else {
|
||||||
tmp->nextCol = elem->nextCol;
|
tmp->nextCol = elem->nextCol;
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
|
|||||||
tmp = tmp->nextRow;
|
tmp = tmp->nextRow;
|
||||||
}
|
}
|
||||||
if (tmp->nextRow == NULL){
|
if (tmp->nextRow == NULL){
|
||||||
return -4; /* WTF ?? */
|
return -4; /* should never happend */
|
||||||
} else {
|
} else {
|
||||||
tmp->nextRow = elem->nextRow;
|
tmp->nextRow = elem->nextRow;
|
||||||
}
|
}
|
||||||
@ -248,15 +248,70 @@ void BasicPrintMatrix(Matrix matrix){
|
|||||||
printf("---END OF MATRIX---\n\n");
|
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){
|
Matrix freeMatrix(Matrix matrix){
|
||||||
|
ListElement * current = NULL;
|
||||||
|
|
||||||
matrix.colCount = 0;
|
matrix.colCount = 0;
|
||||||
matrix.rowCount = 0;
|
matrix.rowCount = 0;
|
||||||
/*il faut free les cellElements car FreeList ne peut pas le faire*/
|
/*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.cols);
|
||||||
FreeList(matrix.rows);
|
FreeList(matrix.rows);
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* todos :
|
/* todos :
|
||||||
*finir le freeMatrix
|
*finir le freeMatrix
|
||||||
*chasser les bugs
|
*chasser les bugs
|
||||||
|
@ -110,7 +110,10 @@ Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows);
|
|||||||
|
|
||||||
void BasicPrintMatrix(Matrix matrix);
|
void BasicPrintMatrix(Matrix matrix);
|
||||||
|
|
||||||
|
bool RecursiveFreeCol(Matrix matrix, cellElement * elem);
|
||||||
|
|
||||||
Matrix freeMatrix(Matrix matrix);
|
Matrix freeMatrix(Matrix matrix);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user