图的邻接表怎么连起来呀?
  • 板块学术版
  • 楼主yxsl
  • 当前回复9
  • 已保存回复9
  • 发布时间2023/5/7 22:18
  • 上次更新2023/10/23 16:22:03
查看原帖
图的邻接表怎么连起来呀?
802842
yxsl楼主2023/5/7 22:18
#include<stdio.h>
#include<stdlib.h>
#define MAX_VERTEX_NUM 20
#define OK 1
#define ERROR -1
typedef int Status;
typedef int InfoType; 
typedef char VertexType;
typedef enum{DG,DN,UDG,UDN} GraphKind;
typedef struct ArcNode
{
	int adjvex;//该弧所指向的顶点的位置
	struct ArcNode *nextarc;//指向下一条弧的指针
	InfoType *info;//该弧相关信息的指针 
}ArcNode;
typedef struct VNode
{
	VertexType data;//顶点信息 
	ArcNode *firstarc;//指向第一条依附该顶点的弧的指针 
}VNode,AdjList[MAX_VERTEX_NUM];
typedef struct
{
	AdjList verticles;
	int vexnum,arcnum;
	int kind;//图的种类 
}ALGraph;

Status CreateALGraph(ALGraph &G)
{
	int i;
	int a,*b;
	ArcNode *p;
	scanf("%d",&G.vexnum);
	for(i=0;i<G.vexnum;i++)
	{
		scanf("%c",&G.verticles[i].data);
		G.verticles[i].firstarc=NULL;
	}
	for(i=0;i<G.vexnum;i++)
	{
		do
		{
			scanf("%d",&a);
			if(a==-1)break;
			scanf("%d",&*b);
			G.verticles[i].firstarc->adjvex=a;
			G.verticles[i].firstarc->info=b;
			
		}while(1);
	}
}

int main()
{
	
return 0;	
}

Status CreateALGraph(ALGraph &G)里面,G.verticles[i].firstarc->nextarc要怎么赋值啊.本人很渣,是大一学数据结构的苦渣,求轻喷。

2023/5/7 22:18
加载中...