#include #include typedef struct aresta { struct vertice *vert; struct aresta *prox; } Aresta; typedef struct vertice { char info; struct aresta *adjacentes; } Vertice; Vertice* CriaVertice(char c) { Vertice *vet = (Vertice*)malloc(sizeof(Vertice)); vet->info = c; vet->adjacentes = NULL; return vet; } Aresta* InsereAdjacente(Vertice *origem, Vertice *adjacente) { Aresta *ar = (Aresta*)malloc(sizeof(Aresta)); ar->vert = adjacente; ar->prox = origem->adjacentes; return ar; } int main () { Vertice *adj[6]; int x; Aresta *p, *t; adj[0] = CriaVertice('u'); adj[1] = CriaVertice('v'); adj[2] = CriaVertice('x'); adj[3] = CriaVertice('y'); adj[4] = CriaVertice('w'); adj[5] = CriaVertice('z'); adj[0]->adjacentes = InsereAdjacente(adj[0], adj[1]); adj[0]->adjacentes = InsereAdjacente(adj[0], adj[2]); adj[1]->adjacentes = InsereAdjacente(adj[1], adj[3]); adj[2]->adjacentes = InsereAdjacente(adj[2], adj[1]); adj[3]->adjacentes = InsereAdjacente(adj[3], adj[2]); adj[4]->adjacentes = InsereAdjacente(adj[4], adj[3]); adj[4]->adjacentes = InsereAdjacente(adj[4], adj[5]); adj[5]->adjacentes = InsereAdjacente(adj[5], adj[5]); for (x = 0; x < 6; x++) { printf("[%c] -> ", adj[x]->info); for (p = adj[x]->adjacentes; p != NULL; p = p->prox) { if (p->prox != NULL) printf("[%c] -> ", p->vert->info); else printf("[%c]", p->vert->info); } printf("\n"); } for (x = 0; x < 6; x++) { p = adj[x]->adjacentes; while(p != NULL) { t = p->prox; free(p); p = t; } free(adj[x]); } return 0; }