graph using djacency matrix c 2b 2b

Solutions on MaxInterview for graph using djacency matrix c 2b 2b by the best coders in the world

showing results for - "graph using djacency matrix c 2b 2b"
24 Nov 2018
1// Adjacency Matrix representation in C++
3#include <iostream>
4using namespace std;
6class Graph {
7   private:
8  bool** adjMatrix;
9  int numVertices;
11   public:
12  // Initialize the matrix to zero
13  Graph(int numVertices) {
14    this->numVertices = numVertices;
15    adjMatrix = new bool*[numVertices];
16    for (int i = 0; i < numVertices; i++) {
17      adjMatrix[i] = new bool[numVertices];
18      for (int j = 0; j < numVertices; j++)
19        adjMatrix[i][j] = false;
20    }
21  }
23  // Add edges
24  void addEdge(int i, int j) {
25    adjMatrix[i][j] = true;
26    adjMatrix[j][i] = true;
27  }
29  // Remove edges
30  void removeEdge(int i, int j) {
31    adjMatrix[i][j] = false;
32    adjMatrix[j][i] = false;
33  }
35  // Print the martix
36  void toString() {
37    for (int i = 0; i < numVertices; i++) {
38      cout << i << " : ";
39      for (int j = 0; j < numVertices; j++)
40        cout << adjMatrix[i][j] << " ";
41      cout << "\n";
42    }
43  }
45  ~Graph() {
46    for (int i = 0; i < numVertices; i++)
47      delete[] adjMatrix[i];
48    delete[] adjMatrix;
49  }
52int main() {
53  Graph g(4);
55  g.addEdge(0, 1);
56  g.addEdge(0, 2);
57  g.addEdge(1, 2);
58  g.addEdge(2, 0);
59  g.addEdge(2, 3);
61  g.toString();
queries leading to this page
graph implementation in cadjacency matrix of a graph code c 2b 2bcreate graph from matrixwrite a program to obtain the adjacency list representation of a graph from its adjacency matrix representation construct graph from adjacency matrixgraph adjacency matrix c 2b 2b codegraph using matrixadjacency list representation of graph in cppimplementation of graphs using adjacency matrixgraph using adjacency matrixhow tyo createa a adjacency list in c 234graph using adjacency list in cadjacency matrix code in cgraph implementation c 2b 2b adjacency matriximplementation of adjacency matrix in c 2b 2bpart3 3a returns the number of edges in the graph int numberofedges 28 29 3b using adjecency matrix in c 2b 2badjacency list c implementationdirected graph using adjacency list in cgraph implementation as a matrixadjacency matrix for graph c 2b 2bc 2b 2b adjacency matrix and listadd edge undirected graph c language adjacency listadjacency matrix in chow to return data to python program from java program to create a graphadd edge to a graph linked listprint a graph algorithm in terminal structuregraph implementation using adjacency matrixfind the vertex c language adjacency listimplement of graph using adjacency matrix in c 2b 2bgraph implementation c 2b 2bexample graph adjacency matrixadjacency matrix graph javahow to make graph from matrix codehow to represent a graph adjacency matrix adjacency list a and b both nonebuild adjacency matrix for a given graph exampleadjacency matrix to a graphcreate adjacency matrix from graphgraph using djacency matrix c 2b 2bcons list java adjacency matrixwrite a c 2b 2b program to implement graph using adjacency matrix c 2b 2b directed graph to matrikadjacency matrix cadjacency matrix repersentation of graph codegraph for adjacency matrixadjacency matrix of a graph c 2b 2bprint adjacency matrix of graph c 2b 2badjacency matrix c 2b 2badjacency matrix graph java only for graph undirected 3fbasic imoemention og graph in c 2b 2bgraph adjacency matrix code in chow to declare graph in c 2b 2bc 2b 2b graph implementation using adjacency matrixmatrix representation of graph in javaadjacency matrix c generate a graph from the given adjacency list 28attached below 2c kindly refer to it 29implementing graph in c 2b 2bhow to do insertion of graph from adjacency matrixdirected graph using adjacency list in c 2b 2badjacency list graph representation in cgraph using djacency matrix c 2b 2b