Establishment and traverse the graph theory [Figure 2]

In c ++ how we should express a picture of it?

How then indicate the completion should call it?

 

1. The establishment figure

There are many ways we live kept a picture, there are the usual csp-s test range of methods:

  2. 1. adjacency matrix array of analog chain (forward star) (of course there are many other methods)

Adjacency matrix of understanding is very simple:

For a two-dimensional array a [i] [j], a [i] [j] is the value of the right side edge of the point i to point j [Note 1] .

Means that we are always right edge from i to j-way side assigned to the corresponding position to keep the two-dimensional array of edge.

void add(int start,int end,int length)
{
    len[start][end]=length;
    len[end][start]=length;
    return;
}

This method is the adjacency matrix of the deposit side, in fact, the "length" to the right side of the non-ij between the value assigned to the len [i] [j] and len [j] [i].

# Note the presence of two assignments here, closer examination reveals that in fact there to keep the two sides ij and ji. [Note 2] we have to reverse by constructing two sides reached simulate the effect of undirected edges.

Guess you like

Origin www.cnblogs.com/rtrtrt/p/12128617.html