Week number |
Professional |
Time |
Other aspects of learning |
Summarize |
|
12 |
The traversal of graphs |
4 hours |
Html |
Still some do not understand, but still learn to study, do not understand to ask! |
|
//
Deep traversal
void Dfsal (graph *g,int i) {
int W;//linknode *p;
p= (struct linknode*) malloc (sizeof (struct linknode))
//
for (int j=0;j<g->n;j++) visited[j]=0;
printf ("%5c", g->vertices[i].data);
Visited[i]=1;
for (Linknode *p=g->vertices[i].first;p;p=p->next) {
w=p->adjvecx;
if (visited[w]==0)
Dfsal (G,W);
}
}
/
Breadth traversal
void Bfsal (graph *g,int i) {
Queue Q;int w,e;
int V;
Linknode *p;
for (int j=0;j<g->n;j++) visited[j]=0;
Visited[i]=1;
printf ("%5c", g->vertices[i].data);
E=i;
Initqueue (Q); Enqueue (q,e);
//
N=isempty (Q);
while (IsEmpty (Q) ==1) {
V=dequeue (Q);
p=g->vertices[v].first;
//
if (p!=null) {
for (Linknode *p=g->vertices[v].first;p=null;p=p->next) {
//
The above loop is not available here or only the first number is output
while (P!=null) {
w=p->adjvecx;
if (visited[w]==0) {
printf ("%c", P->ADJVECX);
printf ("%5c", g->vertices[w].data);
Visited[w]=1; Enqueue (q,w);
Weekly progress bar