forked from codemistic/Data-Structures-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode2.cpp
More file actions
42 lines (37 loc) · 809 Bytes
/
code2.cpp
File metadata and controls
42 lines (37 loc) · 809 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
// adjacency List show
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int inf = 1e9 + 7;
void add_edge(vector<int> vec[], int u, int v)
{
vec[u].push_back(v);
vec[v].push_back(u);
}
void show_list(vector<int> vec[], int list_size)
{
for (int i = 0; i < list_size; i++)
{
cout << i << " --> ";
for (int j = 0; j < vec[i].size(); j++)
{
cout << vec[i][j] << " ";
}
cout << endl;
}
}
int main()
{
int v;
v = 5;
vector<int> adj[v];
// adding all edges
add_edge(adj, 0, 1);
add_edge(adj, 0, 4);
add_edge(adj, 1, 3);
add_edge(adj, 3, 4);
add_edge(adj, 2, 3);
cout << "Check Matrix: " << endl;
show_list(adj, v);
return 0;
}