-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph_00.cpp
More file actions
45 lines (36 loc) · 699 Bytes
/
Copy pathGraph_00.cpp
File metadata and controls
45 lines (36 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
#include<vector>
#include<list>
using namespace std;
class Graph{
int v;
list<int> *l;
public:
Graph(int v){
this->v=v;
l = new list<int> [v];
}
void Add_edge(int u,int v){
l[u].push_back(v);
l[v].push_back(u);
}
void print_Adj_list(){
for(int i=0;i<v;i++){
cout << i << " : " ;
for(int neighbor:l[i]){
cout << neighbor << " ";
}
cout << endl;
}
}
};
int main(){
Graph g(5);
g.Add_edge(0,1);
g.Add_edge(1,2);
g.Add_edge(1,3);
g.Add_edge(2,3);
g.Add_edge(2,4);
g.print_Adj_list();
return 0;
}