Example #1
0
int graph_delete(struct graph *g)
{
	struct vertex *v = g->head;
	for (v = g->head; v != NULL; v = v->next) {
		graph_remove_vertex(g, v);
	}
	return 0;
}
Example #2
0
int graph_remove_vertex_deep(struct graph *g, struct vertex *v)
{
	struct vertex *t;
	for (t = g->head; t != NULL; t = t->next) {
		graph_remove_edge(t, v);
	}
	return graph_remove_vertex(g, v);
}
Example #3
0
void remove_vertex(char *s1, char *s2) {
	int i;
	for(i=0; i<ARRAY_SIZE; i++) {
		if(!vertex[i])
			continue;
		if(!strcmp(s1, vertex[i])) {
			graph_remove_vertex(i);
			return;
		}
	}
}
Example #4
0
void graph_free(graph *g)
{
  int i;
  
  if(g == NULL) {
    return;
  }
  
  /* for vertex in the graph, call the free vertex routine. This will
     free all of the edges too */
  for(i = 0; i < g->max_verticies; i++) {
    graph_remove_vertex(g, i);
  }

  free(g->edges);
  free(g->verticies);
  
  free(g);
}
Example #5
0
int main(){
	setup();

	for(int i=0; i<10; i++){
		graph_add_vertex(gp, u[i]);
	}

	graph_add_edge(gp, u[0], u[1]);
	graph_add_edge(gp, u[0], u[2]);
	graph_add_edge(gp, u[0], u[3]);
	graph_add_edge(gp, u[0], u[4]);

	graph_add_edge(gp, u[1], u[5]);
	graph_add_edge(gp, u[1], u[8]);
	graph_add_edge(gp, u[1], u[2]);

	graph_add_edge(gp, u[2], u[5]);
	graph_add_edge(gp, u[2], u[7]);

	graph_add_edge(gp, u[3], u[1]);
	graph_add_edge(gp, u[3], u[6]);
	graph_add_edge(gp, u[3], u[7]);

	graph_add_edge(gp, u[4], u[5]);

	graph_add_edge(gp, u[5], u[6]);

	graph_add_edge(gp, u[6], u[7]);

	graph_add_edge(gp, u[7], u[8]);

	graph_add_edge(gp, u[8], u[9]);

	graph_add_edge(gp, u[9], u[0]);

	graph_dump(gp, print);

	puts("Drop 0-item");
	graph_drop_vertex(gp, u[0]);
	graph_dump(gp, print);
	puts("");

	puts("Remove 9-item(will failure, because 8-item adjacent to 9-item)");
	graph_remove_vertex(gp, u[9]);
	graph_dump(gp, print);
	puts("");

	puts("Remove edge from 8-item to 9-item");
	graph_remove_edge(gp, u[8], u[9]);
	graph_dump(gp, print);
	puts("");

	puts("Remove 9-item(will success)");
	graph_remove_vertex(gp, u[9]);
	graph_dump(gp, print);
	puts("");	

	puts("Remove edge from 1-item to 5-item");
	graph_remove_edge(gp, u[1], u[5]);
	graph_dump(gp, print);
	puts("");

	puts("Add edge from 1-item to 5-item");
	graph_add_edge(gp, u[1], u[5]);
	graph_dump(gp, print);
	puts("");

	graph_dump(gp, print);


	enddown();
	return 0;
}