-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdijkstra.cpp 1.1
82 lines (73 loc) · 1.51 KB
/
dijkstra.cpp 1.1
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <utility>
#include <string>
#include <map>
using namespace std;
struct node
{
string prev;
int dist;
bool vue;
};
int main()
{
fstream file;
file.open("input.txt");
string valeur;
string pere;
string fils;
int dist;
map < string, node > distMap;
map < string, node >::iterator it;
map < string,vector < pair <string,int> > > graph;
while(file.eof() == false)
{
getline(file, valeur);
stringstream s(valeur);
s >> pere;
cout << "pere: " << pere << " ";
graph[pere];
distMap[pere].dist = -1;
distMap[pere].prev = "-1";
distMap[pere].vue = false;
while(s >> fils)
{
s >> dist;
cout << " -> "<< "fils: " << fils << " distance du pere: " << dist ;
graph[pere].push_back(make_pair(fils,dist));
}
cout<< endl;
}
// soucre = 2
string x = "2";
int smallest = 4294967296;
string nameOfTheSmallest;
while()
{
int i =0;
for(; i< graph[x].size(); i++)
{
distMap[graph[x][i].first].dist = graph[x][i].second;
distMap[graph[x][i].first].prev = x;
if(graph[x][i].second < smallest && distMap[graph[x][i].first].vue != true)
{
smallest = graph[x][i].second;
nameOfTheSmallest= graph[x][i].first;
}
}
for(it = distMap.begin(); it != distMap.end(); it ++)
{
if(it->second.dist < smallest && it->second.vue != true)
{
smallest = it->second.dist;
nameOfTheSmallest = it->first;
}
}
distMap[nameOfTheSmallest].vue = true;
x = nameOfTheSmallest;
}
return 0;
}