Study the code given below carefully. The items you need to complete are below the code. #include #include

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Study the code given below carefully. The items you need to complete are below the code. #include #include

Post by answerhappygod »

Study the code given below carefully. The items you needto complete are below the code.
#include <iostream>
#include <vector>
using namespace std;
//
struct Edge { int src, dest; };
class Graph
{
public:
//
vector<vector<int>> adjList;
Graph(vector<Edge> const &edges, intN)
{
//
adjList.resize(N);
//
for (auto &edge: edges)
{
//
adjList[edge.src].push_back(edge.dest);
}
}
};
//
void printGraph(Graph const& graph, intN)
{
for (int i = 0; i < N; i++)
{
//
cout << i << " --> ";
//
for (int v : graph.adjList)
cout << v << " ";
cout << endl;
}
}
// Graph Implementation using STL
int main()
{
//
vector<Edge> edges =
{
{ 0, 1 }, { 1, 2 }, { 2, 0 }, { 2, 1 },
{ 3, 2 }, { 4, 5 }, { 5, 4 }
};
//
int N = 6;
// construct graph
Graph graph(edges, N);
//
printGraph(graph, N);
return 0;
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply