这个有向图的深度优先遍历 怎么是这样的啊 哪里有问题
#include<stdio.h>#include<stdlib.h>
#define MaxVertexNum 100
typedef char VertexType;
typedef int EdgeType;
typedef struct node
{
int adjvex;
struct node *next;
}EdgeNode;
typedef struct vnode
{
VertexType vertex;
EdgeNode * firstedge;
}VertexNode;
typedef struct
{
VertexNode adjlist[MaxVertexNum];
int n,e;
}ALGraph;
int visited[MaxVertexNum]={0};
//有向图的邻接表存储
ALGraph *creatgraph(ALGraph *G)
{
int i,j,k;
EdgeNode *s,*q,*p;
G=(ALGraph*)malloc(sizeof(ALGraph));
printf("请输入顶点数和边数(顶点数 边数):\n");
scanf("%d %d",&(G->n),&(G->e));
printf("请输入顶点信息):\n");
for(i=0;i<G->n;i++)
{
getchar();
scanf("%c",&(G->adjlist[i].vertex));
G->adjlist[i].firstedge=NULL;
}
printf("请输入边的信息(格式:i j):\n");
for(k=0;k<G->e;k++)
{
scanf("%d %d",&i,&j);
s=(EdgeNode *)malloc(sizeof(EdgeNode));
s->adjvex=j;
s->next=NULL;
p=G->adjlist[i-1].firstedge;
s->next=p;
G->adjlist[i-1].firstedge=s;
}
return G;
}
void DFSAL(ALGraph *G,int i)
{
EdgeNode *p;
printf("%c\n",G->adjlist[i].vertex);
visited[i]=1;
p=G->adjlist[i].firstedge;
while(p!=NULL)
{
if(visited[p->adjvex-1]==0)
{
DFSAL(G,p->adjvex-1);
}
p=p->next;
}
}
//以邻接表为存储结构的图G的深度优先遍历
void DFSTraverseAL(ALGraph *G)
{
int i;
int visited[MaxVertexNum];
for(i=0;i<G->n;i++)
{
visited[i]=0;
}
for(i=0;i<G->n;i++)
{
if(visited[i]==0)
DFSAL(G,i);
}
}
void main()
{
ALGraph *G;
EdgeNode *p;
int i;
G=creatgraph(G);
printf("创建的邻接表是:\n");
for(i=0;i<G->n;i++)
{
p=G->adjlist[i].firstedge;
printf("ok:%c ",G->adjlist[i].vertex);
while(p!=NULL)
{
printf("%d ",p->adjvex);
p=p->next;
}
printf("\n");
}
printf("图的深度优先遍历:\n");
DFSTraverseAL(G);
}