Skip to content
Snippets Groups Projects
Commit 1fc18936 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Add funções para destruir grafo e vértices

parent 9805ceaf
Branches
No related tags found
No related merge requests found
...@@ -111,7 +111,9 @@ void tabuleiroParaGrafo(Tblr t, Grafo g) { ...@@ -111,7 +111,9 @@ void tabuleiroParaGrafo(Tblr t, Grafo g) {
return; return;
} }
int *buscaCaminho(Grafo g) { void destroiGrafo(Grafo g) {
int *caminho = malloc(sizeof(int)); destroiLista(g->vertices, destroiVertice);
return caminho; free(g);
g = NULL;
return;
} }
...@@ -16,6 +16,6 @@ void criaArco(Vertice v, Vertice w); ...@@ -16,6 +16,6 @@ void criaArco(Vertice v, Vertice w);
void tabuleiroParaGrafo(Tblr t, Grafo g); void tabuleiroParaGrafo(Tblr t, Grafo g);
int *buscaCaminho(Grafo g); void destroiGrafo(Grafo g);
#endif #endif
...@@ -11,3 +11,13 @@ Vertice criaVertice() { ...@@ -11,3 +11,13 @@ Vertice criaVertice() {
v->filhos = constroiLista(); v->filhos = constroiLista();
return v; 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;
}
...@@ -13,4 +13,6 @@ typedef struct Vertice *Vertice; ...@@ -13,4 +13,6 @@ typedef struct Vertice *Vertice;
Vertice criaVertice(); Vertice criaVertice();
int destroiVertice(void *v);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment