#include <iostream>
#include <list>
using namespace std;
class Graph{
int V;
list<int> *l;
public:
Graph(int v){
V=v;
l=new list<int> [V];
}
void addEdge(int i, int j, bool undir=true){
l[i].push_back(j);
/*if(undir){
l[j].push_back(i);
}*/
}
void printAdjlist(){
for(int i=0;i<V;i++){
cout<<i<<"-->";
for(auto node:l[i]){
cout<<node<<',';
}
cout<<endl;
}
}
};
int main() {
Graph g(6);
g.addEdge(0, 1);
g.addEdge(0, 4);
g.addEdge(2, 1);
g.addEdge(3, 4);
g.addEdge(4, 5);
g.addEdge(2, 3);
g.addEdge(3, 5);
g.printAdjlist();
}
/*
The undir parameter in addEdge controls whether edges are added bidirectionally (undir = true) or unidirectionally (undir = false).
For undirected graphs, setting undir = true ensures that adding an edge from i to j automatically adds an edge from j to i.
This parameter allows flexibility in defining directed versus undirected graphs based on your specific application requirements.
*/
To embed this project on your website, copy the following code and paste it into your website's HTML: