diff --git a/libs/grafo.c b/libs/grafo.c index d3f94b4727ee6a47566fe365303cf84af7a39813..07774beb7f5120b1d4815b6333ef0a4b058f64f7 100644 --- a/libs/grafo.c +++ b/libs/grafo.c @@ -111,7 +111,9 @@ void tabuleiroParaGrafo(Tblr t, Grafo g) { return; } -int *buscaCaminho(Grafo g) { - int *caminho = malloc(sizeof(int)); - return caminho; +void destroiGrafo(Grafo g) { + destroiLista(g->vertices, destroiVertice); + free(g); + g = NULL; + return; } diff --git a/libs/grafo.h b/libs/grafo.h index aef7000b56610b4f0c198f7944bed8ec5a4f8fc8..cd6a6ab5d1c55efaf1ee448a27eb45114b315040 100644 --- a/libs/grafo.h +++ b/libs/grafo.h @@ -16,6 +16,6 @@ void criaArco(Vertice v, Vertice w); void tabuleiroParaGrafo(Tblr t, Grafo g); -int *buscaCaminho(Grafo g); +void destroiGrafo(Grafo g); #endif diff --git a/libs/vertice.c b/libs/vertice.c index c70a196a5457096cd46254aa54a82f7540f2f8b0..105720b7556fba641fa22fe647f3d6102d5982d9 100644 --- a/libs/vertice.c +++ b/libs/vertice.c @@ -11,3 +11,13 @@ Vertice criaVertice() { v->filhos = constroiLista(); return v; } + +int destroiVertice(void *v) { + Vertice w = (Vertice) v; + // Como os outros vértices também estão no grafo, deixamos isso a cargo dele + destroiLista(w->pais, NULL); + destroiLista(w->filhos, NULL); + free(w); + w = NULL; + return 1; +} diff --git a/libs/vertice.h b/libs/vertice.h index fc061ef37405e26817b9b61e5eb1e02e9ec4c23f..c707a56bb3f80a95aac2f6c1a2644e0e201aac1b 100644 --- a/libs/vertice.h +++ b/libs/vertice.h @@ -13,4 +13,6 @@ typedef struct Vertice *Vertice; Vertice criaVertice(); +int destroiVertice(void *v); + #endif