Question
How do I get the following file to have this information as an output: Attached* is an undirected graph file and shows social interaction between
How do I get the following file to have this information as an output:
Attached* is an undirected graph file and shows social interaction between 62 bottlenose dolphins. Modify Graph.cpp file to find the most and least social dolphins in the community.
Excepted outcome is as follows:
The most social dolphins: 14 with 12 connection(s)
The least social dolphins: 4, 11, 12, 22, 31, 35, 48, 58, 60 with 1 connection(s)
#include
using namespace std;
/***********************************************/ /************ GRAPH CLASS ****************/ /***********************************************/
// Keeps V->Set(neighbor list) // Vector -> Set class Graph { private: int v; // num of vertex int e; // num of edge public: vector< set
Graph::Graph(int n) // constructor { v = n; e = 0; for (int i = 0; i < n; ++i) { this->adj.push_back(set
Explanation:
class BreadthFirstPaths { private: bool *visited; // visited array int *edgeTo; // edgeTo Array int *distTo; // distTo Array int s; // starting vertex int v; // number of vertex
public: BreadthFirstPaths(Graph G, int a); void bfs(Graph G, int a); void showBuffer(); bool hasPathTo(int a); void pathTo(int a); };
BreadthFirstPaths::BreadthFirstPaths(Graph G, int a) { v = G.V(); visited = new bool[v]; // {false}; edgeTo = new int[v]; // {-1}; distTo = new int[v];
for (int i = 0; i < v; ++i) // // while (infile >> a >> b) { visited[i] = false; edgeTo[i] = -1; distTo[i] = -1; }
s = a; // set starting vertex bfs(G, a); }
void BreadthFirstPaths::bfs(Graph G, int a) // Breadth First Search { deque
while (!Q.empty()) { v = Q.front(); // dequeue, access Q.pop_front(); // dequeue, remove set
void BreadthFirstPaths::showBuffer() { cout << setw(7) << "[V]" << setw(11) << "Visited" << setw(9) << "edgeTo" << setw(9) << "distTo" << endl; for (int i = 0; i < v; ++i) // // while (infile >> a >> b) cout << setw(5) << "[" << i << "] " << setw(9) << visited[i] << setw(9) << edgeTo[i] << setw(9) << distTo[i] << endl;
cout << endl; }
int main() { cout << endl ; Graph G1(5); // vertices are 0..4 (N-1)
G1.addEdge(3, 4); G1.addEdge(3, 0); // same as G1.addEdge(0, 3); G1.addEdge(1, 3); G1.addEdge(2, 3);
G1.listEdge(3);
cout << "Degree(3):" << G1.degree(3) << endl; cout << "Degree(2):" << G1.degree(2) << endl;
cout << "Num of Vertices:" << G1.V() << endl; cout << "Num of Edges:" << G1.E() << endl; cout << endl << endl ;
Graph G2("tinyG.txt"); cout << "Num of Vertices (G2):" << G2.V() << endl; cout << "Degree(0):" << G2.degree(0) << endl
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started