血丝玉怎么看真假:帮忙看看这个图的深度优先遍历程序.(C)

来源:百度文库 编辑:高考问答 时间:2024/05/05 03:44:56
#include<stdio.h>
#include<stdlib.h>
struct edgenode
{
int adjvex;
char info;
struct edgenode *next;
};
struct vexnode
{
char data;
struct edgenode *link;
};
typedef struct vexnode adjlist[16];
int e,v;
int vis[16];
adjlist dat;
void depth(struct vexnode *bin);
main()
{
FILE *fp;
int i;
int s,d;
struct edgenode *p,*q;
fp=fopen("c:\date.txt","r");
fscanf(fp,"%d %d",&e,&v);
for(i=1;i<=v;i++)
{
dat[i].data=i;
dat[i].link=NULL;
}
for(i=1;i<=e;i++)
{
vis[i]=0;
fscanf(fp,"%d %d",&s,&d);
p=(struct edgenode *)malloc(sizeof(struct edgenode));
q=(struct edgenode *)malloc(sizeof(struct edgenode));
p->adjvex=d;
q->adjvex=s;
p->next=dat[s].link;
dat[s].link=p;
q->next=dat[d].link;
dat[d].link=q;
}
depth(&dat[1]);
fclose(fp);
getch();
}
void depth(struct vexnode *bin)
{
struct edgenode *p;
p=bin->link;
if(!vis[bin->data])
{
vis[bin->data]=1;
printf("%d",bin->data);
}
while(p!=NULL)
{
if(!vis[bin->data])
{
vis[bin->data]=1;
printf("%d",bin->data);
depth(&dat[bin->data]);
}
p=p->next;
}
}

有错的话就麻烦指出来啊,这么长谁想去分析。