summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--labb3/tsp/src/Tour.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/labb3/tsp/src/Tour.cpp b/labb3/tsp/src/Tour.cpp
index 135e10e..33f14f3 100644
--- a/labb3/tsp/src/Tour.cpp
+++ b/labb3/tsp/src/Tour.cpp
@@ -120,7 +120,7 @@ void Tour::insertNearest(Point p)
Node *node = first->next;
Node *smallestDistanceNode = first; // the node to insert this node after
while (node != first) {
- double distance = node->point.distanceTo(p);
+ double distance = node->point.distanceTo(p); // d1
if (distance < smallestDistance) {
smallestDistance = distance;
smallestDistanceNode = node;
@@ -165,16 +165,16 @@ void Tour::insertSmallest(Point p)
- first->point.distanceTo(first->next->point); // d0
Node *node = first->next;
Node *smallestDiffNode = first; // the node to insert this node after
- do {
- double diff = node->point.distanceTo(p)
- + p.distanceTo(node->next->point)
- - node->point.distanceTo(node->next->point);
+ while (node != first) {
+ double diff = node->point.distanceTo(p) // d1
+ + p.distanceTo(node->next->point) // d2
+ - node->point.distanceTo(node->next->point); // d0
if (diff < smallestDiff) {
smallestDiff = diff;
smallestDiffNode = node;
}
node = node->next;
- } while (node != first); // do-while since `node == first` for the first node
+ }
Node *newNode = new Node(p, smallestDiffNode->next);
smallestDiffNode->next = newNode;
}