/* ECP: FILEname=fig10_28.c */ /* 1*/ typedef int DisType; /* 2*/ #define Infinity IntMax /* 3*/ #define MaxNodes 3000 /* 4*/ typedef struct /* Basic Vertex Structure */ /* 5*/ { /* 6*/ char *NodeName; /* Name */ /* 7*/ DisType Distance; /* Distance From Start */ /* 8*/ int PreviousNode; /* Previous Vertex On Path */ /* 9*/ VarArray Adj; /* List Of Adjacent Vertices */ /*10*/ } Vertex; /* 1*/ int /* 2*/ AddNode( const char *Name, HashTbl H, Vertex Graph[ ] ) /* 3*/ { /* 4*/ int NodeNum; /* 5*/ const Vertex NewVert = { NULL, Infinity, -1, { 0, 0, NULL } }; /* 6*/ if( ( NodeNum = Find( Name, H ) ) < 0 ) /* 7*/ { /* 8*/ NodeNum = Insert( Name, H ); /* 9*/ if( NodeNum == MaxNodes ) /*10*/ { /*11*/ printf( "Graph is full. Increase MaxNodes\n" ); /*12*/ exit( -1 ); /*13*/ } /*14*/ Graph[ NodeNum ] = NewVert; /*15*/ Graph[ NodeNum ].NodeName = Strdup( Name ); /*16*/ } /*17*/ return NodeNum; /*18*/ } /* 1*/ void /* 2*/ AddEdge( int Source, int Dest, Vertex Graph[ ] ) /* 3*/ { /* 4*/ Add( Dest, &Graph[ Source ].Adj ); /* 5*/ }