How to calculate betweenness centrality for adjacency matrix in c ++

  adjacency-matrix, c++

I’m trying to write a simple program to calculate betweenness centrality . I got stuck at getting an output . I read an article to do this but I couldn’t set up its algorithm. adjacency matrix code I created
Screen output should look like this(sample is not real values)

| Nodes    | betweenness centrality |
| -------- | -------------- |
| 1        |       1.3      |
| 2        |        5       |


#include<iostream>
#include <list>
#include <limits.h>
using namespace std;


class Graph
{

    int V;
    list<int> *adj;

public:
    Graph(int V);
    void addEdge(int v, int w);

};

Graph::Graph(int V)
{
    this->V = V;
    adj = new list<int>[V];
}

void Graph::addEdge(int v, int w)
{

    adj[v].push_back(w);
    adj[w].push_back(v);
}

int main()
{
    Graph g1(7);
    g1.addEdge(0, 1);
    g1.addEdge(0, 2);
    g1.addEdge(1, 3);
    g1.addEdge(2, 6);
    g1.addEdge(3, 6);
    g1.addEdge(3, 4);
    g1.addEdge(4, 5);
    g1.addEdge(5, 6);
    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT