Quick actions

cmd+k|ctrl+k

Navigation

Languages

Graph Creation using Method -2 

Snippet info

Language

Cpp

Visibility

public

Author

amangoyal1727

Created

2021-06-13T10:49:48.862859Z

Updated

2021-06-13T10:49:48.862859Z

#include <iostream>
#include<list>
using namespace std;
struct Edge{
    int des;
    int weight;
    
    Edge(int des , int weight){
        this->des = des;
        this->weight = weight;
    }
    
};


int main() {
    
    int V = 7;
    list<pair<int,int>> *l = new list<pair<int,int>>[V];
    l[0].push_back(make_pair(1,10));
    l[0].push_back(make_pair(2,20));
    l[1].push_back(make_pair(2,21));
    l[1].push_back(make_pair(0,10));
    l[2].push_back(make_pair(0,20));
    l[2].push_back(make_pair(1,21));
    
    for(int i=0; i<V; i++){
        for(auto x:l[i]){
            cout<<i<<"->"<<x.first<<"("<<"Weight: "<<x.second<<")"<<endl;
        }
    }
    
    
}
INFO