#include "graph.h" #include #include using namespace std; Graph::Graph(int numVertices):vertexCount(numVertices){ vector v(vertexCount,false); adjacencyMatrix = vector >(vertexCount,v); } void Graph::addEdge(int i, int j) { if (i >= 0 && i < vertexCount && j > 0 && j < vertexCount) { adjacencyMatrix[i][j] = true; adjacencyMatrix[j][i] = true; } } void Graph::removeEdge(int i, int j) { if (i >= 0 && i < vertexCount && j > 0 && j < vertexCount) { adjacencyMatrix[i][j] = false; adjacencyMatrix[j][i] = false; } } bool Graph::isEdge(int i, int j) { if (i >= 0 && i < vertexCount && j > 0 && j < vertexCount) return adjacencyMatrix[i][j]; else return false; } Graph::~Graph() { } int main() { Graph* g = new Graph(3); g->addEdge(1,2); if (g->isEdge(1,2)) { cout << "There is an edge" << endl; }else{ cout << "no edge" << endl; } g->removeEdge(1,2); if (g->isEdge(1,2)) { cout << "There is an edge" << endl; }else{ cout << "no edge" << endl; } delete g; return 1; }