// From the software distribution accompanying the textbook // "A Practical Introduction to Data Structures and Algorithm Analysis, // Third Edition (C++)" by Clifford A. Shaffer. // Source code Copyright (C) 2007-2011 by Clifford A. Shaffer. // Include this file to access Graph representation implemented using an // Adjacency Matrix. #include #include // Used by the mark array #define UNVISITED 0 #define VISITED 1 #include "graph.h" // Implementation for the adjacency matrix representation class Graphm : public Graph { private: int numVertex, numEdge; // Store number of vertices, edges int **matrix; // Pointer to adjacency matrix int *mark; // Pointer to mark array public: Graphm(int numVert) // Constructor { Init(numVert); } ~Graphm() { // Destructor delete [] mark; // Return dynamically allocated memory for (int i=0; i0, "Illegal weight value"); if (matrix[v1][v2] == 0) numEdge++; matrix[v1][v2] = wt; } void delEdge(int v1, int v2) { // Delete edge (v1, v2) if (matrix[v1][v2] != 0) numEdge--; matrix[v1][v2] = 0; } bool isEdge(int i, int j) // Is (i, j) an edge? { return matrix[i][j] != 0; } int weight(int v1, int v2) { return matrix[v1][v2]; } int getMark(int v) { return mark[v]; } void setMark(int v, int val) { mark[v] = val; } }; #include "graphutil.cpp"