#include <stdio.h>
#include <stdlib.h>
#define MAX 4

typedef struct GNode{
	int v;
	int e;
	int w[MAX][MAX];
	char vex[MAX];
	int flag[MAX];
}GNode;

GNode* initGrape(GNode *G)
{
	int i,j;
	G=(GNode *)malloc(sizeof(GNode));
	G->v=MAX;
	G->e=3;

	for(i=0;i<MAX;i++)
		G->vex[i]='A'+i;
	for(i=0;i<MAX;i++)
		G->flag[i]=0;
	for(i=0;i<MAX;i++)
		for(j=0;j<MAX;j++)
		G->w[i][j]=0;
	G->w[0][1]=G->w[1][0]=G->w[0][2]=G->w[2][0]=G->w[1][2]=G->w[2][1]=1;
	G->w[2][5]=G->w[5][2]=G->w[3][7]=G->w[7][3]=G->w[1][9]=G->w[9][1]=1;

	return G;
}
/*void dfs(GNode *G,int n)
{
	int i;
	if(G->flag[n]==0)
	{
		printf("%c",G->vex[n]);
		G->flag[n]=1;
	}
		for(i=0;i<MAX;i++)
		{
			if(G->w[n][i]!=0&&i!=n) dfs(G,G->vex[i]);
		}
	
}*/ 

int main()
{
	int i,j;
	GNode *G=NULL;
	G=initGrape(G);
	printf("\t");
	for(i=0;i<MAX;i++)
	printf("%c\t",G->vex[i]);
	printf("\n");
	for(i=0;i<MAX;i++)
	{
		printf("%c\t",G->vex[i]);
		for(j=0;j<MAX;j++)
			printf("%d\t",G->w[i][j]);
		printf("\n");
	}
	printf("------------dfs-------------\n");
//	dfs(G,2);
	printf("\n");
	return 0;
}

相关文章:

  • 2022-01-12
  • 2022-02-17
  • 2021-12-07
  • 2022-02-21
  • 2022-02-06
  • 2022-01-15
猜你喜欢
  • 2021-10-13
  • 2021-04-08
  • 2021-04-14
  • 2022-01-05
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案