int visited[MAXVEX],A[MAXVEX];
void dfs1(AdjList *q,int vi,int vj,int l,int d)
{
int v,i;
ArcNode *p;
visited[vi]=1;
d++;
A[d]=vi;
if(vi==vj&&d==1)
{
printf(" 一条路径:");
for(i=0;i<=d;i++)
printf("%d",A[i]);
printf("\n");
}
p=g[vi]->firstarc;
while(p!=NULL)
{
v=p->adjvex;
if(visited[v]==0)
dfs1(g,v,vj,l,d);
p=p->nextarc;
}
visited[vi]=0;
d--;
}
void dispcycle(AdjList *q,int vi,int vj,int l,int j)
{
int k;
for(k=0;i<MAXVEX;k++)
visited[k]=0;
dfs1(g,vi,vj,l,-1);
}
void nattolist(AdjMatrix a,AdjList *&g)
{
int i,j,n;
n=a.n;
ArcNode *p;
for(i=0;i<n;i++)
g[i]->firstarc=NULL;
for(i=0;i<n;i++)
for(j=n-1;j>=0;j--)
if(a.edges[i][j]!=0)
{
p=(ArcNode*)malloc(sizeof(Arcnode));
p->adjvex=j;
p->nextarc=g[i]->firstarc;
g[i]->firstarc=p;
}
}
int getnum(AdjList *g)
{
int i,n=0,visited[MAXVEX];
for(i=0;i<MAXVEX;i++)
visited[i]=0;
dfs(g,0);
for(i=0;i<g->n;i++)
if(visited[i]==0)
{
n++;
dfs(g,i);
}
return n;
}
void dfs1(AdjList *g,int v)
{
int i;
ArcNode *p;
int visited[MAXVEX],top=-1,stack[MAXVEX];
for(i=0;i<MAXVEX;i++)
visited[i]=0;
printf("%d ",v);
top++;
stack[top]=v;
visited[v]=1;
while(top>=0)
{
v=stack[top];
top--;
p=g[v]->firstarc;
while(p!=NULL&&visited[p->adjvex]==1)
p=p->nextarc;
if(p==NULL)
top--;
else{
v=p->adjvex;
printf("%d ",v);
visited[v]=1;
top++;
stack[top]=v;
}
}
}
#define MAXVEX 100
struct vertex
{
int num;
char data;
};
typedef struct graph
{
int n;
int e;
struct vertex vexs[MAXVEX];
int edges[MAXNVEX][MAXVEX];
}AdjMatrix;
AdjMatrix creategraph()
{
int i,j,k,w,n,e;
char b,t;
AdjMatrix adj;
printf("顶点数(n)和边数(e):");
scanf("%d%d",&n,&e);
adj.n=n;
adj.e=e;
for(i=0;i<n;i++)
{
printf(" 第%d个顶点的信息:",i+1);
scanf("%c",&adj.vex[i].data);
adj.vex[i].num=i;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
adj.edges[i][j]=0;
for(k=0;k<e;k++)
{
printf("第%d条边:\n",k+1);
printf(" 起点:\n";
scanf("%d",&b);
printf(" 终点:");
scanf("%d",&t);
printf(" 权值:");
scanf("%d",&w);
i=0;
while(i<n&&adj.vexs[i].data!=b)
i++;
if(i>=n)
}
}