예제 #1
0
파일: exp9-2.cpp 프로젝트: sloopie/liuw
int main(int argc, char **argv)
{
	int i,j;
	MGraph g;
	ALGraph *G;
	int A[MAXV][6] = {
		{ 0, 5, 0, 7, 0, 0},
		{ 0, 0, 4, 0, 0, 0},
		{ 8, 0, 0, 0, 0, 9},
		{ 0, 0, 5, 0, 0, 6},
		{ 0, 0, 0, 5, 0, 0},
		{ 3, 0, 0, 0, 1, 0}};
	g.n = 6;
	g.e = 10;
	for (i = 0; i < g.n; i++)		
		for (j = 0;j < g.n; j++)
			g.edges[i][j] = A[i][j];
	G = (ALGraph *)malloc(sizeof(ALGraph));
	MatToList(g,G);			
	printf("1:\n");
	DispAdj(G);
	printf("2:\n");
	DFS(G,0);
	printf("\n");
	printf("3:\n");
	DFS1(G,0);
	printf("4:\n");
	BFS(G,0);
	printf("\n");
	return 0;
}
예제 #2
0
void main()
{ 
	ALGraph *G;
	int mg[M+2][N+2]={							//迷宫数组
		{1,1,1,1,1,1},
		{1,0,0,0,1,1},
		{1,0,1,0,0,1},
		{1,0,0,0,1,1},
		{1,1,0,0,0,1},
		{1,1,1,1,1,1}};	
	CreateList(G,mg);
	printf("迷宫对应的邻接表:\n");DispAdj(G);	//输出邻接表
	PathType path;
	path.length=0; 
	printf("所有的迷宫路径:\n");
	FindPath(G,1,1,M,N,path);
}