Can you tell me my mistake?
Check i have edited your code ->
also it’s not printing right answer for dij call cause of your dij function.
Implement it like this
void dijkstra(T src)
{
unordered_map<T, int> dist;
//set all the distances to infinity
for(auto l:mp)
{
dist[l.first]=INT_MAX;
}
set<pair<int ,T> > s;
dist[src]=0;
s.insert(make_pair(0,src));
while(!s.empty())
{
//find the pair at the front.
auto p=*(s.begin());
T node=p.second;
int nodeDist=p.first;
//begin wale ka fix karr diya hamne ab isko erase kr do or iske neighbours ko insert kar do
s.erase(s.begin());
//Iterate over the neighbours of the current node
for(auto childpair:mp[node])
{
if(nodeDist + childpair.second < dist[childpair.first])
{
//int the set , updation of a particular is not possible
//we have to remove the old pair, and insert the new pair to simulation pudation
T dest = childpair.first;
auto f = s.find(make_pair(dist[dest],dest));
if(f!=s.end())
{
s.erase(f);
}
dist[dest]=nodeDist + childpair.second;
s.insert(make_pair(dist[dest],dest));
}
}
}
for(auto d:dist)
{
cout<<d.first<<" is located at a distance of "<<d.second<<" from "<<src<<"\n";
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.