-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.cpp
36 lines (31 loc) · 913 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
#include <iostream>
#include "graph.h"
std::map<int,std::list<std::pair<int,int>>> Graph::getVertices(){
return vertices;
}
void Graph::insertNode(int node){
auto exist = vertices.find(node);
if(exist==vertices.end()){
std::list<std::pair<int,int>> list;
vertices.insert(std::make_pair(node,list));
}else{
std::cout << "Node with same name already exist!" << std::endl;
}
}
void Graph::insertEdge(int from,int to,int cost){
auto exist = vertices.find(from);
if(exist!=vertices.end()){
exist->second.push_back(std::make_pair(to,cost));
}else{
std::cout << "Node "<< from << " does not exist!" << std::endl;
}
}
std::list<std::pair<int,int>> Graph::getNeightboursOfNode(int node){
auto exist = vertices.find(node);
if(exist!=vertices.end()){
return exist->second;
}else{
std::cout << "Node "<< node << " does not exist!" << std::endl;
return {};
}
}