Exemple #1
0
int main(int argc, char *argv[]){
	char filename[MAX_FILE_NAME];
	int vertex_num;
	int origin_num;
	char line[MAX_LINE];
	
	FILE *in;
	if(argc != 2){
		printf("Usage: ./%s [filename]\n", argv[0]);
		exit(1);
	}
	strcpy(filename, argv[1]);
	if((in = fopen(filename, "r")) == NULL){
		fprintf(stderr, "failed to open the file\n");
	}
	while(fgets(line, MAX_LINE, in)!=NULL){
		int vertex[MAX_NODES_NUM];
		int matrix[MAX_NODES_NUM][MAX_NODES_NUM];
		int num = parse(line,vertex);
		decode(matrix, vertex, num);
		//print_matrix(matrix, num);
		graph *graph_ptr = create_graph(matrix,num);
		//print_graph(graph_ptr);
		DFSTraversal(graph_ptr);
		BFSTraversal(graph_ptr);
	}
	if(fclose(in)!=0){
		fprintf(stderr, "failed to close the file\n");
	}

}
int main()
{
	/*graph *g=createGraph(8);
	addEdge(g,1,2);
	addEdge(g,2,3);
	addEdge(g,8,2);
	addEdge(g,3,4);
	addEdge(g,3,5);
	addEdge(g,5,6);
	addEdge(g,5,7);
	addEdge(g,5,8);*/
	graph *g=createGraph(6);
	addEdge(g,6,3);
    addEdge(g,6,1);
    addEdge(g,4,1);
    addEdge(g,5,2);
    addEdge(g,3,4);
    addEdge(g,4,2);
	DFSTraversal(g);
	printf("\n");
	head=NULL;
	BFSTraversal(g);
	printf("\n");
	topologicalsort(g);
	return 0;
}
Exemple #3
0
int main()
{

  struct Graph * graphInstance = createAdjMatrixGraph();
  //printGraph(graphInstance);  
  int Visited[graphInstance->V];
  DFSTraversal(graphInstance,Visited);

  return 0;
}