图的应用----最短路径(C++)

# include 
# include 
# include 
# include 
# define INFINITY 1000
# define MAX_VERTEX_NUM 20
# define OK 1
# define ERROR 0 
# define FALSE 0
# define TRUE 1
typedef enum{
DG,DN,UDG,UDN
} GraphKind;
typedef int EType;
typedef int InfoType;
typedef int VertexType;
typedef int PathMatrix;
typedef int ShortPathTable; 
 
typedef struct ArcCell
{
  EType adj;
   InfoType info;
 
}ArcCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
 
typedef struct
{
  VertexType vexs[MAX_VERTEX_NUM];
   AdjMatrix  arcs;
   int vexnum,arcnum;
   GraphKind kind;
 
}MGraph;
 
int CreatUDN(MGraph &G)                                 //CreatUDN() function
{
  int i=0,j=0,k,vi,vj,w;
   cout<<"Please input the number of G.vexnum (eg,G.vexnum=6) : ";
   cin>>G.vexnum;
   cout<<"Please input the number of G.arcnum (eg,G.arcnum=8) : ";
   cin>>G.arcnum;
   for(i=0;iVj):"<>vi;
       cout<<"Please input the "<>vj;
       cout<<"Please input the "<>w;
       i=vi;
       j=vj;
       while(i<1||i>G.vexnum||j<1||j>G.vexnum||w<0||w>=INFINITY)
       {
    
   cout<<"Input ERROR!"<>vi;
   cout<<"Please input the "<>vj;
   cout<<"Please input the "<>w;
   i=vi;
   j=vj;
        
}//end of while
   i--;
   j--;         
   G.arcs[i][j].info=w;
    
}//end of for(k=0;k
image.png

你可能感兴趣的:(图的应用----最短路径(C++))