Home > Back-end >  Write a simple graph traversal, bosses, please point out where I went wrong
Write a simple graph traversal, bosses, please point out where I went wrong

Time:12-01

# include
# include
# define Max 100
# define NULL 0
Typedef struct Arcnode {char adjvex; Struct Arcnode * nextarc; Int the info; } arcnode, * arc;
Typedef struct {char data; Arcnode * firstarc; } vnode adlist [Max];
Typedef struct {adlist are; Int vexnum arcnum; } algraph;
Int the locate (algraph a, char STR)
{int I; for(i=0; I Void bianli algraph (a)
{int I;
The arc b;
for(i=0; I {b=Dr. Ertices [I] firstarc; Printf (" % c ", Dr. Ertices [I] data);
While (b!=NULL)
{printf (" -> "% c, b -> adjvex); B=b -> nextarc; }}
}
Void main ()
{int I, j, k; Char v1, v2, Algraph G; The arc p1. The arc p2. The scanf (" % d % d ", & G.a rcnum, & G.v exnum); for(i=0; I for(i=0; I {the scanf (" % c ", & v1); The scanf (" % c ", & v2); J=locate (G, v1); K=locate (G, v2); P1=(arc) malloc (sizeof (arcnode)); P1 -> adjvex=G.v ertices [k]. Data; P1 -> nextarc=G.v ertices [j]. J firstarc; G.v ertices [j] firstarc=p1; P2=(arc) malloc (sizeof (arcnode)); The p2 -> adjvex=G.v ertices [j]. Journal of data; The p2 -> nextarc=G.v ertices [k]. Firstarc; G.v ertices [k]. Firstarc=p2; }
Bianli (G); }