I want to make adjacency list representation of graph using vector
and when we declare vector
as global variable where the memory is allocated to vector in stack or heap
#include<bits/stdc++.h>
#include<vector>
using namespace std;
void addedge(vector<int> &graph, int u, int v) {
graph[u].push_back(v);
graph[v].push_back(u);
}
void printgraph(const vector<int> &gph) {
for (int v = 0 : gph) {
cout << v;
for (auto x : gph[v]) {
cout << x;
printf("\n");
}
}
}
int main() {
vector<int> gph;
addedge(gph, 2, 3);
addedge(gph, 6, 7);
addedge(gph, 1, 2);
printgraph(gph);
}