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
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -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
......@@ -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;
}
......@@ -13,4 +13,6 @@ typedef struct Vertice *Vertice;
Vertice criaVertice();
int destroiVertice(void *v);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment