-
Notifications
You must be signed in to change notification settings - Fork 1
/
graph.cpp
40 lines (38 loc) · 864 Bytes
/
graph.cpp
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
/*
* Graph.cpp
*
* Created on: 25.12.2018
* Author: aegan123
*/
#include "graph.h"
#include <iostream>
using namespace std;
Graph::Graph(){
this->graph = new vector<pair<int,int>>;
}
/*
Graph::~Graph(){
delete graph;
}
*/
void Graph::addEdge(int node1, int node2, int weight){
graph[node1].push_back(make_pair(node2, weight));
graph[node2].push_back(make_pair(node1, weight));
}
// Print adjacency list representaion ot graph
void Graph::printGraph(int V)
{
int v, w;
for (int u = 0; u < V; u++)
{
cout << "Node " << u << " makes an edge with \n";
for (auto it = graph[u].begin(); it!=graph[u].size(); it++)
{
v = it->first;
w = it->second;
cout << "\tNode " << v << " with edge weight ="
<< w << "\n";
}
cout << "\n";
}
}