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;
}
Study the code given below carefully. The items you need to complete are below the code. #include #include
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am