Adjacency Matrix:
1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cstring>5 using namespacestd;6 7typedefCharvertextype[4];8typedefintVrtype;9 #defineINF 100000Ten #defineMax 20 One Atypedefstruct /*fixed point*/ - { -Vrtype adj;/*Weighted Value*/ the }arcnode,adjmatrix[max][max]; -typedefstruct /*Chart Type*/ - { -Vertextype Vex[max];/*Storage Point*/ +Adjmatrix arc;/*adjacency Matrix*/ - intVexnum,arcnum;/*fixed point, number of sides*/ + }mgraph; A at voidCreategraph (Mgraph *N); - voidDisplay (Mgraph N); - intLocate (Mgraph *n,Char*v); - - intMain () - { in mgraph N; -Creategraph (&N); to Display (N); + } - intLocate (Mgraph *n,Char*v) the { * inti; $ for(i=0; i<n->vexnum;i++)Panax Notoginseng if(strcmp (v,n->vex[i]) = =0) - returni; the return-1; + } A voidCreategraph (Mgraph *N) the { + - Vertextype v1,v2; $ Vrtype W; $cout<<"input point, number of edges"<<Endl; -Cin>>n->vexnum>>n->Arcnum; - inti,j,k; thecout<<"Enter a fixed-point name"<<Endl; - for(i=0; i<n->vexnum;i++)/*Enter a fixed-point name*/WuyiCin>>n->Vex[i]; the - for(i=0; i<n->vexnum;i++)/*Initialize*/ Wu { - for(j=0; j<n->vexnum;j++) About { $n->arc[i][j].adj=INF; - } - } -cout<<"Input Edge Weight value"<<Endl; A for(k=0; k<n->arcnum;k++) + { theCin>>v1>>v2>>W; -I=Locate (N,V1); $j=Locate (N,V2); then->arc[i][j].adj=W; the } the } the voidDisplay (mgraph N) - { in inti,j,k; the for(i=0; i<n.vexnum;i++) the { About for(j=0; j<n.vexnum;j++) the { thecout<<n.arc[i][j].adj<<" "; the } +cout<<Endl; - } the}
Adjacency Matrix, adjacency table