Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include // std::ifstream #include #include #include #include // containers that store unique elements following a specific order.

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 > adj; // adjacency Graph(int n); Graph(const string &filename); int V(); int E(); void addEdge(int a, int b); bool haveEdge(int a, int b); int degree(int a); void listEdge(int a); };

Graph::Graph(int n) // constructor { v = n; e = 0; for (int i = 0; i < n; ++i) { this->adj.push_back(set()); // Insert a set of int for each vexter

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 Q; // Queue to keep vertices to be visited Q.push_back(a); // enqueue, insert an item visited[a] = true; distTo[a] = 0; int v;

while (!Q.empty()) { v = Q.front(); // dequeue, access Q.pop_front(); // dequeue, remove set::iterator it; for ( it = G.adj[v].begin(); it != G.adj[v].end(); ++it) { if (!visited[*it]) { Q.push_back(*it); visited[*it] = true; edgeTo[*it] = v; distTo[*it] = distTo[v] + 1; } } } }

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

How to design a balanced scorecard for a new business venture

Answered: 1 week ago