diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-09-21 16:11:29 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-09-21 16:11:29 +0200 |
| commit | 56dc03a2791f6d2bec86285fed1a12907d7ff661 (patch) | |
| tree | c02e41c49742d78fec1219c35f5641c192515034 /labb3/tsp | |
| parent | 8b6a241faee1e0d9aac9281be7be883ba0332ac1 (diff) | |
| download | tddd86-56dc03a2791f6d2bec86285fed1a12907d7ff661.tar.gz | |
Minor comments
Diffstat (limited to 'labb3/tsp')
| -rw-r--r-- | labb3/tsp/src/Tour.cpp | 12 |
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; } |
