# include & lt; stdio.h>
#include
100//# define MaxNum maximum vertex number
# define STACKSIZE 100
Typedef struct ArcNode//table node
{
Int adjvex;//deposit table node vertex domain
Struct ArcNode * nextarc;//pointer to the next table node
} ArcNode;
Typedef struct VexNode
{
char data;//the vertex information
ArcNode * firstarc;//pointer to the first table node
} VexNode AdjList [MaxNum];//AdjList said adjacency table type
Typedef struct
{
AdjList are drawn.//head node array
Int vexnum arcnum;//figure on the number of the current vertex and edge
} ALGraph;
Typedef struct
{
Int * top;
Int * base;
Int stacksize;
} the stack;
Typedef struct
{
Char * top;
Char * base;
Int nodesize;
} the Node;
Int main ()
{
Int I, num, a;
Int choice;//select menu variable
ALGraph G;//define adjacency table structure G
Stack p;//define the stack structure p
Do
{
Printf (" \ n tasks a \ n ");
Printf (" 1, create adjacency list undirected graph \ n ");
Printf (" 2, inventory \ n ");
Printf (" 3, read disk \ n ");
Printf (" 4, initialization of the stack and the stack \ n ");
Printf (" 5, out of the stack \ n ");
Printf (" 6, destruction of the stack \ n ");
Printf (" 7, depth first search traversal undirected graph \ n ");
Printf (" 8, print adjacency table \ n ");
Printf (" please input your choice \ n ");
The scanf (" % d ", & amp; Choice);
System (" CLS ");//clear screen
The fflush (stdin);//remove input buffer
Switch (choice)//according to choose, different function called
to complete the various tasks{
Case 1:
CreatGraph (& amp; G);
break;
Case 2:
Filewrite (G);
break;
Case 3:
Fileread (G);
break;
Case 4:
If (InitStack (& amp; P)==1)
{
Printf (" how much do you want to input elements into the stack, ");
The scanf (" % d ", & amp; Num);
Printf (" please enter the % d element (input an element after press the return key to enter the next) : \ n ", num);
for(i=1; i{
The scanf (" % d ", & amp; A);
Push (& amp; P, a);
}
Print (& amp; P);
Printf (" \ n \ n stack elements: % d ", getTop (& amp; P, num));
}
break;
Case 5:
Printf (" the stack ");
Pop (& amp; P, num);
Print (& amp; P);
break;
Case 6:
Destorystack (& amp; P);
break;
Case 8:
PrintGraph (G);
break;
Default:
Printf (" invalid choice!!! Please input again!!!!!! \n");
break;
}
}
While (choice!=99);
return 0;
}
Void CreatGraph (ALGraph * G)//create the adjacency list
{
int i,j,k;
Char m, n;
ArcNode * s;
Printf (" input the total number of vertices and the total number of edges, input after the completion of the carriage return (such as: 4 (2) \ n ");
The scanf (" % d % d ", & amp; G - & gt; Vexnum, & amp; G - & gt; Arcnum);//input to the total number of vertices, the total number of edges
getchar();//read only one character at a time after press enter
Printf (" input value of each vertex input after the completion of the carriage return (e.g. abcd) \ n ");
for(i=0; i{
The scanf (" % c ", & amp; G - & gt; Are [I]. Data);//input vertex value
}
for(i=0; i{
G - & gt; Are [I] firstarc=NULL;//initialize the header node to NULL pointer domain
}
int length;
Length=G - & gt; Vexnum;
For (k=0; K{
Printf (" input each edge of the two nodes, the input after the completion of the return to the input (such as: a, b) \ n ");
The scanf (" % c % c ", & amp; M, & amp; N);//enter an edge two nodes m and n
S=(ArcNode *) malloc (sizeof (ArcNode));//to generate a new node
S - & gt; Adjvex=n;//n deposit to the table node vertex domain
for(i=0; i{
If (m==G - & gt; Are [I] data)//if the execution will be inconsistent
{
S - & gt; Nextarc=G - & gt; Are [I] firstarc;//head interpolation method to establish a new node
////head next head node array pointer to the first table node I
//a pointer per cycle s under a head node are each group of the first table node
G - & gt; Are [I] firstarc=s;//pointer assignment s end nodes of the array first table node
}
}
S=(ArcNode *) malloc (sizeof (ArcNode));//generate another symmetrical new edge node
S - & gt; Adjvex=m;//m deposit to the table node vertex domain
for(j=0; J{
If (n==G - & gt; Are [j]. Journal of data)//if the execution will be inconsistent
{
S - & gt; Nextarc=G - & gt; Are [j] firstarc;////head next head node array pointer to the first table node j
G - & gt; Are [j] firstarc=s;
}
}
}
}
Void printGraph (ALGraph G)//print adjacency list
{
int i;//loop variable
ArcNode * p;
Printf (" adjacency list has been created! \n");
for(i=0; i{
Printf (" % c: ", G.v ertices [I] data);//print header node
For (p=G.v ertices [I] firstarc; p; P=p - & gt; Nextarc)//a pointer p initial value for each group of adjlink to the first element of the pointer p to the back of the extension, only to the pointer pointing to the empty p
{
Printf (" % c ", p - & gt; Adjvex);//print the vertex field
}
printf("\n");//print a newline after exit the loop
}
}
Int InitStack (stack * p)//initializes the
{
P - & gt; The base=(int *) malloc (sizeof (int) * STACKSIZE);
if(! P - & gt; Base)
return 0;
P - & gt; Top=p - & gt; The base;
P - & gt; Stacksize=stacksize;
return 1;
}
Int a push (stack * p, int e)//stack
{
If ((p - & gt; Top - p - & gt; Base) & gt;=p - & gt; Stacksize)
{
P - & gt; The base=realloc (p - & gt; Base, (STACKSIZE + 10) * sizeof (int));
if(! P - & gt; Base)
exit(0);
P - & gt; Top=p - & gt; Base + p - & gt; Stacksize;
P - & gt; Stacksize=stacksize + 10;
}
* (p - & gt; Top) + +=e;
return 1;
}
Pop (stack * p is int, int) e//the stack
{
If (p - & gt; The base==p - & gt; Top)
exit(0);
E=* (- p - & gt; Top);
return 1;
}
Int getTop (stack * p, int e)//take the top element
{
If (p - & gt; The base==p - & gt; Top)
exit(0);
E=* (p - & gt; Top - 1);
return e;
}
Int destorystack (stack * p)//destroy
{
Free (p - & gt; Base);
P - & gt; The base=NULL;
P - & gt; Top=NULL;
P - & gt; Stacksize=0;
if(! P - & gt; Base)
Printf (" stack is destroyed success!!!!!! \n");
return 1;
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull