这个有向图广度优先遍历哪里错了 帮忙看看
#include <stdio.h>
#include <malloc.h>
#define MAX_VERTEX_NUM 100
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
typedef int Status;
typedef int VRType;
typedef char VertexType;
typedef char InfoType;
typedef enum {DG,DN,UDG,UDN}GraphKind;
typedef char QElemType;
int visited[MAX_VERTEX_NUM];
typedef struct ArcCell
{
VRType adj;
InfoType *info;
}ArcCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
typedef struct
{
VertexType vexs[MAX_VERTEX_NUM];
AdjMatrix arcs;
int vexnum,arcnum;
GraphKind kind;
}MGraph;
typedef struct QNode
{
QElemType data;
struct QNode *next;
}QNode,*QueuePtr;
typedef struct
{
QueuePtr front;
QueuePtr rear;
}LinkQueue;
Status InitQueue(LinkQueue &Q)
{
Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode));
if(!Q.front) return ERROR;
Q.front->next=NULL;
return OK;
}
Status EnQueue(LinkQueue &Q,QElemType e)
{
QueuePtr p;
p=(QueuePtr)malloc(sizeof(QNode));
if(!p) return ERROR;
p->data=e;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
return OK;
}
Status DeQueue(LinkQueue &Q,QElemType &e)
{
QueuePtr p;
if(Q.front==Q.rear)
return ERROR;
p=Q.front->next;
Q.front->next=p->next;
if(Q.rear==p)
Q.rear=Q.front;
free(p);
return OK;
}
int LocateVex(MGraph G,VertexType v)
{
int j=-1,k;
for(k=0;k<G.vexnum;k++)
if(G.vexs[k]==v)
{
j=k;
break;
}
return j;
}
Status CreateUDN(MGraph &G)
{
int i,j,k;
VertexType v1,v2;
scanf("%d%d",&G.vexnum,&G.arcnum);
getchar();
for(i=0;i<G.vexnum;i++)
scanf("%c",&G.vexs[i]);
for(i=0;i<G.vexnum;i++)
for(j=0;j<G.vexnum;j++)
G.arcs[i][j].adj=0;
for (k=0;k<G.arcnum;k++)
{
getchar();
scanf("%c%c",&v1,&v2);
i=LocateVex(G,v1);j=LocateVex(G,v2);
G.arcs[i][j].adj=1;
}
return OK;
}
Status first(MGraph G,int v)
{
int j;
for(j=0;j<G.vexnum;j++)
if(G.arcs[v][j].adj==1)
return j;
return -1;
}
Status next(MGraph G,int v,int w)
{
int j;
for(j=w+1;j<G.vexnum;j++)
if(G.arcs[v][j].adj==1)
return j;
return -1;
}
void guangdu(MGraph G)
{
int j,w,v;
LinkQueue Q;
for(v=0;v<G.vexnum;v++)
visited[v]=0;
InitQueue(Q);
for(v=0;v<G.vexnum;v++)
if(!visited[v])
{
visited[v]=TRUE;
printf("%c",G.vexs[v]);
EnQueue(Q,G.vexs[v]);
while(Q.front!=Q.rear)
{
DeQueue(Q,G.vexs[v]);
for(w=first(G,v);w!=-1;w=next(G,v,w))
if(!visited[w])
{ visited[w]=true;
printf("%c",G.vexs[w]);
EnQueue(Q,G.vexs[w]);
}
}
}
}
int main()
{
MGraph G;
CreateUDN(G);
guangdu(G);
printf("n");
return 0;
}