1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-29 22:04:13 +00:00
This commit is contained in:
Antoine Bartuccio 2016-12-11 02:32:51 +01:00
parent 24e3bb4b90
commit 10d6da9be6
2 changed files with 23 additions and 17 deletions

View File

@ -23,6 +23,14 @@ cellElement * CreateCellElem(){
return elem; return elem;
} }
bool is_leaf(cellElement* tree){
if (tree->nextCol == NULL && tree->nextRow == NULL){
return true;
} else {
return false;
}
}
int AddNextCol(cellElement* tree){ int AddNextCol(cellElement* tree){
cellElement * elem = NULL; cellElement * elem = NULL;
@ -60,7 +68,7 @@ int AddNextRow(cellElement* tree){
elem->value = true; elem->value = true;
elem->nextRow = NULL; elem->nextRow = NULL;
elem->nextRow = NULL; elem->nextCol = NULL;
if (tree->nextRow == NULL){ if (tree->nextRow == NULL){
tree->nextRow = elem; tree->nextRow = elem;
}else{ }else{
@ -73,9 +81,7 @@ void removeNextCol(cellElement* tree){
printf("---removeNextCol---\n"); printf("---removeNextCol---\n");
if (tree->nextCol != NULL){ if (tree->nextCol != NULL){
cellElement * elem = tree->nextCol; free(tree->nextCol);
free(elem);
elem = NULL;
tree->nextCol = NULL; tree->nextCol = NULL;
} }
@ -85,9 +91,7 @@ void removeNextRow(cellElement* tree){
printf("---removeNextRow---\n"); printf("---removeNextRow---\n");
if (tree->nextRow != NULL){ if (tree->nextRow != NULL){
cellElement* elem = tree->nextRow; free(tree->nextRow);
free(elem);
elem =NULL;
tree->nextRow = NULL; tree->nextRow = NULL;
} }
@ -95,16 +99,16 @@ void removeNextRow(cellElement* tree){
void recursivePrint(cellElement * tree){ void recursivePrint(cellElement * tree){
if (tree != NULL){ if (tree != NULL){
printf("Elem : x: %d y: %d \n",tree->colIndex,tree->rowIndex); printf("Elem : x: %d y: %d \n",tree->colIndex,tree->rowIndex);
if (tree->nextCol != NULL){ if (is_leaf(tree)){
recursivePrint(tree->nextCol);
}
if (tree->nextRow != NULL){
recursivePrint(tree->nextRow);
}
if (tree->nextCol == NULL && tree->nextCol == NULL){
printf("leaf\n"); printf("leaf\n");
} else {
if (tree->nextCol != NULL){
recursivePrint(tree->nextCol);
}
if (tree->nextRow != NULL){
recursivePrint(tree->nextRow);
}
} }
} }
} }

4
main.c
View File

@ -16,15 +16,17 @@ int main(int argc, char **argv){
cellElement * tree = NULL; cellElement * tree = NULL;
tree = CreateCellElem(); tree = CreateCellElem();
tree->colIndex = 1; tree->colIndex = 1;
tree->rowIndex = 1;
AddNextRow(tree); AddNextRow(tree);
tree->nextRow->colIndex = 2; tree->nextRow->colIndex = 2;
tree->nextRow->rowIndex = 2;
AddNextCol(tree); AddNextCol(tree);
tree->nextCol->colIndex = 3; tree->nextCol->colIndex = 3;
tree->nextCol->rowIndex = 2;
recursivePrint(tree); recursivePrint(tree);
removeNextRow(tree); removeNextRow(tree);
removeNextCol(tree); removeNextCol(tree);
recursivePrint(tree);
return 0; return 0;