I'm having an issue on accessing the function of the class "graph" to another class. Inside of class "Jeepney" there are 2 function wherein the first one is to add an edge and the second one is to get the shortest path using the function of the class "graph" wherein the problem is when I accessing the function from class "graph" it seem that there is no added edges. In this program I'm intended to create a undirected graph and access the shortest path.
CLASS GRAPH:
This is the "add_edge" function that adds an edge in the graph:
public:
//ADD EDGES
void add_edge(T key_name, T connected_node, int distance, bool undirected = true){
map[key_name].push_back(std::make_pair(connected_node, distance));
if(undirected){
map[connected_node].push_back(std::make_pair(key_name, distance));
}
}
CLASS JEEPNEY
This is the function calls the function "add_edges" in the graph class to add an edge from the another class.
auto create_graph(){
Graph<T> G;
G.add_edge("Marikina","Manila",1);
G.add_edge("Manila","Pasig",4);
G.add_edge("Pasig","Manila",2);
return G;
}
This is a function is same class with the "create_graph" function wherein I needed to access the class "graph" functions and it didn't print something but I already created a graph in the function ""create_graph", it seems that the edges of the graph isn't created when accessing it this function.:
void search_shortest_path(){
create_graph();
Graph<T> G;
std::cout<<"AVAILABLE ROUTES\n";
G.print_all_key();
T source;
T destination;
std::cout<<"Enter your starting point: ";
std::cin>>source;
std::cout<<"Enter your destination point: ";
std::cin>>destination;
G.dijkstra_algorithm(source, destination);
}