Skip to content
Snippets Groups Projects
Commit 792e47f6 authored by dario.genga's avatar dario.genga
Browse files

some edits

parent d41b0862
No related branches found
No related tags found
No related merge requests found
......@@ -90,23 +90,29 @@ void transform(node *qt, int size, int indices[size]) {
}
}
void destroy(node *tree) {
void destroy(node *tree, int depth) {
if (tree == NULL) {
return;
}
if (is_leaf(tree)) {
free(tree);
return;
}
for (int i = 0; i < 4; i++) {
destroy(tree->child[i]);
node *current = tree->child[i];
for (int k = 0; k < depth; k++) {
if (is_leaf(current)) {
free(current);
} else {
current = tree->child[k]->child[i];
}
}
}
free(tree);
}
int main() {
int row = QUADTREE_SIZE;
int col = QUADTREE_SIZE;
int depth = 4;
int parcours[2] = {3, 1};
int matrix[16][16] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 3, 3, 3, 3, 0, 0, 7, 7, 7, 7, 0, 0, 11, 11, 11},
......@@ -125,8 +131,7 @@ int main() {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 3, 3, 3, 3, 0, 0, 7, 7, 7, 7, 0, 0, 11, 11, 11}
};
int parcours[2] = {3, 1};
node* qTree = create_tree_from_matrix(row, col, matrix, 4);
node* qTree = create_tree_from_matrix(row, col, matrix, depth);
transform(qTree, 3, parcours);
for (int r = 0; r < row; r++) {
......@@ -136,5 +141,6 @@ int main() {
printf("\n");
}
destroy(qTree, depth);
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment