Chinaunix首页 | 论坛 | 博客
  • 博客访问: 121919
  • 博文数量: 41
  • 博客积分: 1695
  • 博客等级: 上尉
  • 技术积分: 430
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-21 22:50
文章分类

全部博文(41)

文章存档

2010年(1)

2007年(23)

2006年(17)

我的朋友

分类: C/C++

2007-01-18 20:31:28

#include
#include
#define MAX_VERTEX_NUM  20

typedef enum {DG, DN, AG, AN}GraphKind;
typedef struct ArcNode
{
	int adjvex;
	struct ArcNode *nextarc;
//	int info;
}ArcNode;
typedef struct VNode
{
	char data;
	struct ArcNode *firstarc;
}VNode, AdjList[MAX_VERTEX_NUM];

typedef struct
{
	AdjList vertices;
	int vernum, arcnum;
	GraphKind kind;
}Graph;

int Locate(Graph G, char ch)
{
	int i;
	for(i=0; ikind);
	getchar();
	printf("\nPlease input the number of vertices:");
	scanf("%d", &G->vernum);
	getchar();
	printf("\nPlease input the number of arcs:");
	scanf("%d", &G->arcnum);
	getchar();
	switch(G->kind)
	{
		case DG:
			for(i=0; ivernum; i++)
			{
				printf("\nPlease input the data of the %dth vertices:", i);
				scanf("%c", &G->vertices[i].data);
				getchar();
				G->vertices[i].firstarc = NULL;
			}
			for(i=0; iarcnum; i++)
			{
				printf("\nPlease input the start-point and end-point of the %dth arc:", i);
				scanf("%c%c", &v1, &v2);
				getchar();
				j = Locate(*G, v1);
				k = Locate(*G, v2);
				p = (ArcNode *)malloc(sizeof(ArcNode));
				p->adjvex = k;
				p->nextarc = G->vertices[j].firstarc;
				G->vertices[j].firstarc = p;
			}
			break;

		default:
			break;

	}
}

void display(Graph G)
{
	int i;
	ArcNode *p;
	for(i=0; iadjvex]);
			p = p->nextarc;
		}
		printf("\n");
	}

}

main()
{
	Graph graph;
	Create(&graph);
	display(graph);
}
阅读(1232) | 评论(0) | 转发(0) |
0

上一篇:八皇后问题

下一篇:C实现cat功能

给主人留下些什么吧!~~