#include<stdio.h>
#include<string.h>
#define MAX_VEX 20
#define TURE 1
#define FALSE 0
#define ERROR 0
#define NULL 0
typedef int status;
typedef struct ArcNode{
int adjvex;
int weight;
struct ArcNode *nextarc;
}ArcNode;
typedef struct Vnode{
char date;
ArcNode * firstarc;
}Vnode,Adjlist;
typedef struct{
int vexnum;
int arcnum;
Adjlist vertices[ MAX_VEX];
}Algrapgh;
///////////////////
int Locatevex(Algrapgh G,char v)
{
for(int i=0;i<G.vexnum;i++)
if(G.vertices[i].date==v)
return i;
else {
printf("找不到顶点位置\n");
return ERROR;
}
}
/////////////////////
void CreatAlgrapgh(Algrapgh & G)
{ //以邻接表的形式构造图
char v1,v2;
int w;
ArcNode *p;
scanf("&G.vexnum,&G.arcnum");
for(int i=0;i<G.vexnum;i++)
{ scanf (" &G.vertices[i].date,");
G.vertices[i].firstarc=NULL;
}
for(int k=0;k<G.arcnum;k++)
{ int i=0;int j=0;
scanf(&v1,&v2,&w);
i=Locatevex(G,v1);
j=Locatevex(G,v2);
p=new ArcNode;
if(!p)
return ;
else{
p->adjvex=j;
p->weight=w;
p->nextarc=G.vertices[i].firstarc;
G.vertices[i].firstarc=p;
}
}
//////////////////
void DFS(Algrapgh G,int v)
{//从第v个顶点深度访问
if(!visited[v])
{
visited[v]=TURE ;
printf("%c",&G.vertices[i].date);
p=G.vertices[i].firstarc;
while(p)
{
DFS(G,v);
p=p->nextarc;
}
}
}
////// ////////////
void DEFTraverse(Algrapgh G)
{//深度优先遍历
for(int v=0;v<G.vexnum;v++)
visited[v]=FALSE;//访问标志数组
for(int v=0 ;v<G.vexnum;v++)
if(!visited[v]) DFS(G,v);
}
//////////////////////
///////////////
void main()
{
Algrapgh G;
CreatAlgrapgh(G);
DEFTraverse( G)
}
我对编译产生的错误不明白?请问高手能否帮我看一下?仔细讲一下啊谢谢啊!
把改后的程序copy在上面了谢谢