建立一个含有五个顶点的无向图的邻接表,并完成它的深度优先序列。
急~~~下面是我写的程序,不过有些问题,谁能帮我改改啊???
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define maxvernum 100
typedef struct node
{
int adjvex;
struct node *next;
}nodetype;
typedef struct frontnode
{
int data;
struct node *next;
}frontnodetype;
frontnodetype adjlist[maxvernum];
/*********************************************/
void main()
{
void dfs(frontnodetype g[],int v,int c[]);
void travelgraph(frontnodetype g[],int n);
frontnodetype adjlist[6];
int i,j,m;
for(i=1;i<=5;i++)
{
printf("请输入第%d个表头结点:",i);
scanf("%d",&adjlist[i].data);
adjlist[i].next=NULL;
}
for(j=1;j<=5;j++)
{
printf("进入第%d次循环/n",j);
printf("开始输入前请输入一个不为0的m值以便输入/n");
scanf("%d",&m);
while(m!=0)
{
int x;
printf("请输入结点序号(x=0表示后面没有结点):/n");
if(x!=0)
{
scanf("%d",&x);
nodetype *p;
p=(nodetype *)malloc(sizeof(nodetype));
p->adjvex=x;p->next=NULL;
p->next=adjlist[j].next;
adjlist[j].next=p;
}
else break;
printf("是否停止?(m为0时停止输入,m为1时继续输入。)/n");
scanf("%d",&m);
}
}
printf("深度优先搜索序列为:/n");
travelgraph(&adjlist[1],5);
}
/************************************************/
void dfs(frontnodetype g[],int v,int c[])
{
int i;
nodetype *p;
c[v]=1;
printf("%d/n",v);
for(p=g[v].next;p!=NULL;p=p->next)
{
i=p->adjvex;
if(c[i]==0)
dfs(g,i,c);
}
}
/************************************************/
void travelgraph(frontnodetype g[],int n)
{
int v;
int c[maxvernum];
for(v=1;v<=n;v++)
c[v]=0;
for(v=1;v<=n;v++)
if(c[v]==0)
dfs(g,v,c);
}