-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpath.cpp
71 lines (56 loc) · 1.57 KB
/
path.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
/*
* File: path.cpp
* --------------
* Name: [TODO: enter name here]
* Section: [TODO: enter section leader here]
* This file implements the path.h interface.
*/
/////////////////////////////////////////////////////////////////////
// Your task in this part of the assignment is to write the code //
// that implements your path.h interface. For the benefit of //
// future programmers who will need to work on this interface, //
// you must also write an extended comment (presumably replacing //
// this to-do box) that documents the design decisions you made //
// in structuring the Path class as you did. //
/////////////////////////////////////////////////////////////////////
// [TODO: implement the methods in your Path class]
#include "path.h"
#include "gpathfinder.h"
Path::Path() {
totalCost = 0;
}
Path::~Path() {
}
double Path::pathCost() {
return totalCost;
}
string Path::toString() {
string pathString = "";
if (path.size()==0) return pathString;
pathString = path[0]->start->name;
foreach (Arc *arc in path) {
pathString += "->";
pathString += arc->finish->name;
}
return pathString;
}
void Path::add(Arc* arc) {
path.add(arc);
totalCost += arc->cost;
}
bool Path::isEmpty() {
return path.isEmpty();
}
void Path::removeLastArcTraversed(){
totalCost = totalCost - (path[path.size()-1]-> cost);
path.removeAt(path.size()-1);
}
void Path::clear(){
path.clear();
}
Vector<Arc *> Path::returnPath(){
return path;
}
Arc *Path::getFinalArc() {
return path[path.size() - 1];
}