My code is giving error kindly check it

#include
#include
using namespace std;
class Graph{
int V;
list *l;
// l is array of lists
public:
Graph(int V)
{
this->V=V;
l=new list[V];
}

	void addEdge(int x,int y)
	{
		l[x].push_back(y);
		l[y].push_back(x);
	}
	void printAdjlist(){
		//Iterate over all the vertices
		for(int i=0;i<V;i++)
		{
			cout<<"Vertex "<<i<<"->"
			for(int nbr:l[i])
			{
				cout<<nbr<<",";
			}
			cout<<endl;
		}
	}

};
int main()
{
Graph g(4);
g.addEdge(0,1);
g.addEdge(0,2);
g.addEdge(2,3);
g.addEdge(1,2);
// printAdjlist();
}

#include #include using namespace std; class Graph{ int V; list *l; // l is array of lists public: Graph(int V) { this->V=V; l=new list[V]; } void addEdge(int x,int y) { l[x].push_back(y); l[y].push_back(x); } void printAdjlist(){ //Iterate over all the vertices for(int i=0;i<V;i++) { cout<<“Vertex “<<i<<”->”; for(int nbr:l[i]) { cout<<nbr<<","; } cout<<endl; } } }; int main() { Graph g(4); g.addEdge(0,1); g.addEdge(0,2); g.addEdge(2,3); g.addEdge(1,2); // printAdjlist(); }

hi @devyanshbansal123
refer this -->


and from next time kindly save ur code on coding blocks ide and send link, instead of pasting the code over here in text box…

what and where was mistake in my code sir?

@devyanshbansal123
save ur code on coding blocks ide and send link… will check where u were going wrong…

hi @devyanshbansal123


I have corrected ur code… its working fine now…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

sir can you tell me where did you made changes i am not able to find one