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.cppfile 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 > 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 { 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 for (int i = 0; i < v; ++i) // // while (infile >> a >> b) cout

cout }

int main() { cout 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 cout

cout cout cout

Graph G2(\"tinyG.txt\"); cout cout

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

Step: 3

blur-text-image

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions