# Include <iostream> using namespace STD; typedef char vertextype; typedef int edgetype; # define maxvex 100 # define infinity 1000 class mgraph {public: vertextype vexs [maxvex]; edgetype arc [maxvex] [maxvex]; int numvertexs, numedges; // Number of vertices in the graph and number of edges in the graph mgraph (const Int & V, const Int & E ): numvertexs (V), numedges (e) {} void creategraph (); // create a graph structure void displaygraph (); // display the graph structure}; void mgraph :: creategraph () {cout <"Enter the element type value of the vertex. The number of inputs is" <numvertexs <Endl; For (INT I = 0; I <numvertexs; ++ I) {CIN> vexs [I];} cin. clear (); cout <"assign values to the adjacent matrix. The size of the matrix is:" <numvertexs <"*" <numvertexs <Endl; for (INT I = 0; I <numvertexs; ++ I) {for (Int J = 0; j <numvertexs; ++ J) {CIN> arc [I] [J] ;}} void mgraph: displaygraph () {cout <"the elements in the vertex are output below" <Endl; for (INT I = 0; I <numvertexs; ++ I) {cout <vexs [I] <"" ;}cout <Endl; for (INT I = 0; I <numvertexs; ++ I) {for (Int J = 0; j <numvertexs; ++ J) {cout <arc [I] [J] <'\ T';} cout <Endl ;}} int main () {mgraph g (); G. creategraph (); G. displaygraph (); System ("pause"); Return 0 ;}
The method of representing the adjacent matrix in the Data Structure