An introduction to the non-direction graph of adjacency table
The non-direction graph of adjacency table refers to the graph represented by adjacency table.
The above figure G1 contains "a,b,c,d,e,f,g" a total of 7 vertices, and contains "(A,c), (A,d), (a,f), (B,c), (C,d), (E,g), (f,g)" A total of 7 sides.
The matrix to the right of the above figure is the G1 intention of the adjacency representation in memory. Each vertex contains a list of linked lists that record the ordinal number of the vertex's adjacency point. For example, the 2nd vertex (vertex C) contains a list of nodes containing the data of the node is "0,1,3", and this "0,1,3" corresponding to the "a,b,d" ordinal number, "A,b,d" are the adjacent points of C. is to record the information of the graph in this way.
Code description for non-direction graph of adjacency table
1. Basic definition
public class LISTUDG {
//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
...
}
LISTUDG 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 LISTUDG (char[) vexs, char[][] edges) {
Initializes the number of vertices and the 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);
Initialize Node2 enode node2 = new Enode ();
Node2.ivex = p1; Link Node2 to the end of the P2 list if (Mvexs[p2].firstedge = null) Mvexs[p2].firstedge = Node2;
else Linklast (Mvexs[p2].firstedge, Node2); }
}
The function is to create an adjacency table without a graph. In fact, this method creates a G1 graph, which is the diagram above. The calling code is as follows:
Char[] Vexs = {' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G '};
char[][] edges = new char[][]{
{' A ', ' C '}, {' A ', ' d '}, {' A ', ' F '}, {'
B ', ' C '}
, {' C ', ' d '}, {'
E '}, ' , ' G '},
{' F ', ' G '}};
LISTUDG PG;
PG = new Listudg (vexs, edges);
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/