git » orga2-tp1.git » commit 5a5d259

Implementar destruirArbol

author Rodrigo Campos
2011-04-10 00:05:15 UTC
committer Rodrigo Campos
2011-04-10 00:05:15 UTC
parent 6787248965874873b7a2d3e1fcb92bd31d5d4f33

Implementar destruirArbol

bintree.asm +20 -0
test.c +6 -3

diff --git a/bintree.asm b/bintree.asm
index dbf53c6..af54533 100644
--- a/bintree.asm
+++ b/bintree.asm
@@ -460,6 +460,7 @@ buscar_min:
 	ret
 
 
+; void destruirArbol(nodo * arbol);
 destruirArbol:
 	push ebp
 	mov ebp, esp
@@ -467,7 +468,26 @@ destruirArbol:
 	push esi
 	push ebx
 
+	mov ebx, [ebp + 8]
+	%define .nIzq [ebx + off_izq]
+	%define .nDer [ebx + off_der]
+
+	cmp ebx, 0
+	je .fin
+
+	push dword .nIzq
+	call destruirArbol
+	add esp, 4
 
+	push dword .nDer
+	call destruirArbol
+	add esp, 4
+
+	push ebx
+	call free
+	add esp, 4
+
+.fin:
 	pop ebx
 	pop esi
 	pop edi
diff --git a/test.c b/test.c
index fd02260..508ccb4 100644
--- a/test.c
+++ b/test.c
@@ -35,9 +35,6 @@ int main()
 	printf("31 == %d\n", e->izq->der->id);
 
 	printf("Hola puto\n");
-	//eliminar(&e, 30);
-	//eliminar(&e, 31);
-	eliminar(&e, 32);
 
 	printf("id de la raiz es: %d\n", e->id);
 	if (e->der == NULL)
@@ -47,5 +44,11 @@ int main()
 	printf("1º hijo: %d\n", e->izq->id);
 	printf("2º hijo: %d\n", e->izq->der->id);
 
+//	eliminar(&e, 32);
+//	eliminar(&e, 30);
+//	eliminar(&e, 31);
+//	eliminar(&e, 34);
+	destruirArbol(e);
+
 	return 0;
 }