An introduction to the graph of adjacency table
The direction graph of adjacency table refers to a direction graph expressed by adjacency table.
The above figure G2 contains a total of 7 vertices of "a,b,c,d,e,f,g" and contains "<A,B>,<B,C>,<B,E>,<B,F>,<C,E>,<D,C>" <E,B>,<E,D>,<F,G> "A total of 9 sides.
The matrix to the right of the above figure is the G2 intention of the adjacency representation in memory. Each vertex contains a list of linked lists that record the ordinal number of the other vertex corresponding to the vertex. For example, a 1th vertex (vertex B) contains a list of nodes that contain data that is "2,4,5", and this "2,4,5" corresponds to the ordinal number of "c,e,f", and "c,e,f" to the other vertex of the out side of B.
A code description of the adjacency table's direction graph
1. Basic definition
public class LISTDG {
//adjacency table table corresponding to the vertex of the list
private class Enode {
int ivex; The position of the vertex pointed to by the Edge is Enode nextedge/////////The vertex of the table in the
adjacency table is
private class Vnode {
char data; Vertex information
Enode Firstedge; Point to the first arc attached to the vertex
;
Private vnode[] Mvexs; Vertex array
...
}
LISTDG is the corresponding structure of the adjacency table. Mvexs is a one-dimensional array that holds vertex information.
The Vnode is the corresponding structure of the vertex of the adjacency table. Data is what the vertex contains, and Firstedge is the header pointer to the list that the vertex contains.
Enode is the corresponding structure of the nodes of the linked list contained in the vertex of the adjacency table. Ivex is the index of the vertex corresponding to the node in Vexs, and Nextedge refers to the next node.
2. Create a matrix
This provides two ways to create matrices. One is with known data , and the other requires the user to enter data manually .
2.1 Creating the diagram (with the provided matrix)
* * * Create diagram (with provided matrix) * Parameter Description: * vexs-vertex array * edges-edge Array/public LISTDG (char[) Vexs, char[][] Edge
s) {//Initialize "vertex number" and "number of edges" int vlen = vexs.length;
int elen = Edges.length;
Initialize "vertex" Mvexs = new Vnode[vlen];
for (int i = 0; i < mvexs.length i++) {mvexs[i] = new Vnode ();
Mvexs[i].data = Vexs[i];
Mvexs[i].firstedge = null;
}//Initialize "Edge" for (int i = 0; i < Elen i++) {//read edge start vertex and end vertex char c1 = edges[i][0];
char C2 = edges[i][1];
Reads the starting and ending vertices of the edges int p1 = getPosition (edges[i][0]);
int P2 = getPosition (edges[i][1]);
Initialize Node1 enode node1 = new Enode ();
Node1.ivex = p2;
Link Node1 to the end of the P1 list if (Mvexs[p1].firstedge = null) Mvexs[p1].firstedge = Node1;
else Linklast (Mvexs[p1].firstedge, Node1); }
}
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/