From 56dc03a2791f6d2bec86285fed1a12907d7ff661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 21 Sep 2020 16:11:29 +0200 Subject: Minor comments --- labb3/tsp/src/Tour.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'labb3/tsp/src/Tour.cpp') 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; } -- cgit v1.2.1