예제 #1
0
void main()
{
	int ch;
	do
	{
		clrscr();
		printf("\t\tDijkstra Shortest Path Algorithm\n");
		printf("\t\t--------------------------------");
		printf("\n\t\t0. Exit");
		printf("\n\t\t1. Create Adjacency Matrix");
		printf("\n\t\t2. Lowest cost adjacency Matrix");
		printf("\n\t\t3. Find smallest path between (u,v)\n");
		printf("\n\tYour Choice-> ");
		scanf("%d",&ch);
		switch(ch)
		{
			case 1:
					clrscr();
					create_adj_mat();
					break;
			case 2:
					clrscr();
					dijkstra(G,n);
					getch();
					break;
			case 3:
					clrscr();
					show_smallest(cost);
					getch();
					break;
		}
	}while(ch!=0);
}
void create_graph(){
	scanf("%d %d",&nVertices , &nEdges);
	int i,a,b;
	igraph_vector_t v;
	igraph_vector_init (&v, 2*nEdges);
	for(i=0;i<2*nEdges;i+=2){
		scanf("%d %d",&a,&b);
		if(a>nVertices || b>nVertices){
			printf("vertex id overflow : %d-%d\n",a,b);
			break;
		}
		VECTOR(v)[i]=a;
		VECTOR(v)[i+1]=b;
	}
	igraph_create(&g, &v, 0, 1);
	create_adj_mat();
}