急求修改下,总是有错误
# include<stdio.h>
# include <malloc.h>
# define null 0
#define MAXVEX 100
typedef int Vertex;
struct arcnode
{ int adjvex;
struct arcnode *nextarc;};
struct node{
int data;
struct arcnode *firstarc;};
typedef struct node algraph[MAXVEX+1];
void creat (algraph g,int e,int n)
{struct arcnode *p;
int i,j,k;
printf("请输入顶点信息");
for (i=1;i<=n;i++)
{scanf ("%d",&g[i].data);
g[i].firstarc=null;}
for (k=1;k<=e;k++)
{printf ("请输入边的两个顶点");
scanf ("%d%d",&i,&j);
p=(struct arcnode *)malloc(sizeof(struct arcnode));
p->adjvex=i;
p->nextarc=g[j].firstarc;
g[j].firstarc=p;
}
void oupe (algraph g,int n)
{
int i;
struct arcnode *p;
for (i=1;i<=n;i++)
{
p=g[i].firstarc;
printf("%d",g[i].data);
while (p!=null)
{printf("%d",p->adjvex);
p=p->nextarc;
}
printf("\n");
}
}
int visited [101]={0};
void dfs(algraph g,int i)
{
struct arcnode *p;
printf("%d",g[i].data);
visited[i]=1;
p=g[i].firstarc;
while (p!=null)
{if (visited[p->adjvex]==0)
dfs(g,p->adjvex);
p=p->nextarc;
}
}
main()
{
algraph g;
int e,n,i;
printf("请输入顶点个数和边的个数");
scanf("%d%d",&n,&e);
creat(g,e,n);
oupe(g,n);
printf("输入从第几个顶点开始遍历:");
scanf("%d",&i);
dfs(g,i);
}