-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatalog.cpp
84 lines (62 loc) · 2.39 KB
/
catalog.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
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
83
84
/*************************************************************************
catalog
-------------------
début : 27/11/2023
copyright : (C) 2023 par Jixiang, Adam, Clément, Louis
binome : B3311 et B3309
*************************************************************************/
//---------- Réalisation de la classe <Catalog> (fichier Catalog.cpp) ------------
//---------------------------------------------------------------- INCLUDE
//-------------------------------------------------------- Include système
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
using std::ostream;
//------------------------------------------------------ Include personnel
#include "catalog.h"
//----------------------------------------------------- Méthodes publiques
void Catalog::Search(const char *const from, const char *const to,
PathNode *pathNode)
// Algorithme :
// A DFS Search is used to find all the possible journeys.
{
if (!strcmp(from, to)) {
LinkedList<Journey> path;
while (pathNode && pathNode->pjourney) {
path.Add(pathNode->pjourney, false);
pathNode = pathNode->lastPathNode;
}
for (Node<Journey> *nodeJourney = path.GetFirst(); nodeJourney;
nodeJourney = nodeJourney->next) {
cout << *(nodeJourney->pdata) << endl;
}
cout << endl;
return;
}
if (!pathNode) {
pathNode = &pathRoot;
}
for (Node<Journey> *nodeJourney = journeyLinkedList.GetFirst(); nodeJourney;
nodeJourney = nodeJourney->next) {
if (!strcmp(nodeJourney->pdata->GetFrom(), from)) {
PathNode *checkPathNode = pathNode;
bool alreadyUsed = false;
while (checkPathNode && checkPathNode->pjourney) {
if (checkPathNode->pjourney == nodeJourney->pdata)
alreadyUsed = true;
checkPathNode = checkPathNode->lastPathNode;
}
if (alreadyUsed)
continue;
PathNode *nextPathNode = new PathNode{nodeJourney->pdata, pathNode};
pathNode->nextPathNodes.Add(nextPathNode);
Search(nodeJourney->pdata->GetTo(), to, nextPathNode);
}
}
} //----- Fin de Search
//------------------------------------------------- Surcharge d'opérateurs
ostream &operator<<(ostream &os, const Catalog &catalog) {
catalog.show('\n');
return os;
} //----- Fin de operator <<