An Introduction to an undirected graph of an adjacent table an undirected graph is an undirected graph represented by an adjacent table. The figure G1 above contains "A, B, C, D, E, F, G" 7 vertices in total and contains "(A, C), (, d), (A, F), (B, C), (C, D), (E, G), (F, G) "7 sides in total. The matrix on the right is the neighboring table in memory of G1. Each vertex contains a linked list, which records "the serial number of the adjacent vertex of the vertex ". For example, the data of the nodes contained in the linked list contained in the 2nd vertex (vertex C) is ", 3", and the ", 3" corresponds to "A, B, d. "A, B, D" are the adjacent contacts of C. In this way, the information of the graph is recorded. Code Description of undirected graph in the adjacent table 1. basic definition copy Code # define MAX 100 // adjacent table class ListUDG {private: // internal class // vertex class ENode {public: int ivex; // ENode * nextEdge of the vertex pointed to by this edge; // pointer to the next arc}; // vertex class VNode {public: char data in the list of adjacent tables; // vertex information ENode * firstEdge; // point to the first arc attached to the vertex}; private: // private member int mVexNum; // The number of vertices in the graph int mEdgNum; // Number of edges of the graph VNode mVexs [MAX]; public: // create the graph corresponding to the adjacent table (input by yourself) ListUDG (); // create the graph corresponding to the adjacent table (use the provided Data) ListUDG (char vexs [], int vlen, char edges [] [2], int elen );~ ListUDG (); // print the void print () of the adjacent table graph; private: // read an input character char readChar (); // return the position int getPosition (char ch) of ch ); // link the node to the final void linkLast (ENode * list, ENode * node) of the list;}; copy the code (01) ListUDG is the structure of the adjacent table. MVexNum is the number of vertices, mEdgNum is the number of edges, and mVexs is a one-dimensional array that stores vertex information. (02) VNode is the struct corresponding to the vertex of the adjacent table. Data is the data contained in the vertex, and firstEdge is the header pointer of the linked list contained in the vertex. (03) ENode is the struct corresponding to the node of the linked list contained in the vertex of the adjacent table. Ivex is the index of the vertex corresponding to the node in vexs, while nextEdge points to the next node. 2. Create a matrix. Here we provide two methods to create a matrix. One is to use known data, and the other needs to be manually input data. 2.1 create a graph (using the provided matrix) copy the code/** create the graph corresponding to the adjacent table (using the provided data) */ListUDG: ListUDG (char vexs [], int vlen, char edges [] [2], int elen) {char c1, c2; int I, p1, p2; ENode * node1, * node2; // initialize "vertex count" and "edge count" mVexNum = vlen; mEdgNum = elen; // initialize the vertex for (I = 0; I <mVexNum; I ++) {mVexs [I]. data = vexs [I]; mVexs [I]. firstEdge = NULL;} // initialize the edge of the "adjacent table" for (I = 0; I <mEdgNum; I ++) {// start vertex and end vertex of the read edge c1 = edges [I] [0]; c2 = edges [I] [1]; p1 = getPosition (c1); p2 = getPosition (c2); // initialize node1 node1 = new ENode (); node1-> ivex = p2; // link node1 to "The end of the p1 linked list" if (mVexs [p1]. firstEdge = NULL) mVexs [p1]. firstEdge = node1; else linkLast (mVexs [p1]. firstEdge, node1); // initialize node2 node2 = new ENode (); node2-> ivex = p1; // link node2 to "The end of the p2 linked list" if (mVexs [p2]. firstEdge = NULL) mVexs [p2]. firstEdge = node2; else linkLast (mVexs [p2]. firstEdge, no De2) ;}} copy the Code. This function is used to create an undirected graph of an adjacent table. In fact, the undirected graph created by this method is figure G1 above. The call code is as follows: copy the code char vexs [] = {'A', 'B', 'C', 'D', 'E', 'F ', 'G'}; char edges [] [2] = {'A', 'C'}, {'A', 'D'}, {'A ', 'F'}, {'B', 'C'}, {'C', 'D'}, {'E', 'G'}, {'F ', 'G' }}; int vlen = sizeof (vexs)/sizeof (vexs [0]); int elen = sizeof (edges)/sizeof (edges [0]); listUDG * pG; pG = new ListUDG (vexs, vlen, edges, elen); copy code 2.2 to create a graph (input by yourself) copy the code/** create the graph corresponding to the adjacent table (input by yourself) */ListUDG: ListUDG () {char c1, c2; int v, e; int I, p1, P2; ENode * node1, * node2; // enter "number of vertices" and "number of edges" cout <"input vertex number:"; cin> mVexNum; cout <"input edge number:"; cin> mEdgNum; if (mVexNum <1 | mEdgNum <1 | (mEdgNum> (mVexNum * (mVexNum-1 )))) {cout <"input error: invalid parameters! "<Endl; return;} // initialize the vertex of the" adjacent table "for (I = 0; I <mVexNum; I ++) {cout <"vertex (" <I <"):"; mVexs [I]. data = readChar (); mVexs [I]. firstEdge = NULL;} // initialize the edge of the "adjacent table" for (I = 0; I <mEdgNum; I ++) {// read the start vertex and end vertex cout of an edge <"edge (" <I <"):"; c1 = readChar (); c2 = readChar (); p1 = getPosition (c1); p2 = getPosition (c2); // initialize node1 node1 = new ENode (); node1-> ivex = p2; // link node1 to "The end of the p1 linked list" if (mV Exs [p1]. firstEdge = NULL) mVexs [p1]. firstEdge = node1; else linkLast (mVexs [p1]. firstEdge, node1); // initialize node2 node2 = new ENode (); node2-> ivex = p1; // link node2 to "The end of the p2 linked list" if (mVexs [p2]. firstEdge = NULL) mVexs [p2]. firstEdge = node2; else linkLast (mVexs [p2]. firstEdge, node2) ;}} copy the Code. This function reads user input and converts the input data to an undirected graph.