Adjacency List Implementation of the Graph

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> using namespace std; #include <vector>; int main() { int nodes; int edges; cin>>nodes>>edges; int x,y; vector<int> A[10]; //Loop for making the edges for(int i=0; i<edges; ++i){ cin>>x>>y; A[x].push_back(y); } //For printing the graph in form of edges and nodes for(int i=1; i<=nodes; ++i){ cout<<"Adjacency List Of the graph is: "<<i<<": "; for(int j=0; j<A[i].size();++j){ if(j==A[i].size()-1){ cout<<A[i][j]<<endl; } else cout<<A[i][j]<<" --> "; } } }
Editor Settings
Theme
Key bindings
Full width
Lines