小白写数据结构中 用邻接表表示图并输出中 在调试界面出现了问题
program received signal SIGSEGV,Segmentation fault
并不是很懂
#include<iostream>
#include<stdio.h>
#define MVNum 100
typedef struct ArcNode //边节点
{
int adjvex;
struct ArcNode * nextarc;
}ArcNode;
typedef struct VNode //顶点节点
{
char data;
ArcNode * firstarc;
}VNode, AdjList[MVNum];
typedef struct //邻接表
{
AdjList vertices;
int vexnum, arcnum;
}ALGraph;
int LocateVex(ALGraph N,char v)
{
int i;
for(i=0;i<N.vexnum;i++)
{
if(N.vertices[i].data==v)
return i;
}
}
int CreateUDG(ALGraph &G)
{
int i,j,k,v1,v2;
ArcNode *p1,*p2;
std::cin>>G.vexnum>>G.arcnum;
for(i=0;i<G.vexnum;i++)
{
std::cin>>G.vertices[i].data;
G.vertices[i].firstarc=NULL;
}//顶点节点(4个)全部排在了数组里面;
for(k=0;k<G.arcnum;k++)
{
std::cin>>v1>>v2;
i=LocateVex(G,v1);
j=LocateVex(G,v2);
p1=new ArcNode;
p1->adjvex=j;
p1->nextarc=G.vertices[i].firstarc;
G.vertices[i].firstarc=p1;
p2->adjvex=i;
p2->nextarc=G.vertices[j].firstarc;
G.vertices[j].firstarc=p1;
}
}
int main()
{
int i;
ALGraph G;
ALGraph *p;
ArcNode *pp;
CreateUDG(G);
for(i=0;i<G.vexnum;i++)
{
std::cout<<p->vertices[i].data;
std::cout<<"->";
pp=p->vertices[i].firstarc;
do
{
std::cout<<pp->adjvex;
pp=pp->nextarc;
}while(pp==NULL);
printf("\n");
}
}