summaryrefslogtreecommitdiffstats
path: root/labb3
diff options
context:
space:
mode:
Diffstat (limited to 'labb3')
-rw-r--r--labb3/tsp/src/Tour.cpp14
-rw-r--r--labb3/tsp/src/Tour.h2
-rw-r--r--labb3/tsp/src/tsp.cpp11
3 files changed, 13 insertions, 14 deletions
diff --git a/labb3/tsp/src/Tour.cpp b/labb3/tsp/src/Tour.cpp
index 33f14f3..5c63ad2 100644
--- a/labb3/tsp/src/Tour.cpp
+++ b/labb3/tsp/src/Tour.cpp
@@ -11,19 +11,17 @@ Tour::Tour()
Tour::~Tour()
{
if (!first) {
- cout << "Empty tour" << endl;
return;
}
- // since node is freed, we need to keep track of next as well
Node *node = first;
- Node *next = first->next;
- do {
+ Node *next;
+ while (node->next != first) {
+ next = node->next;
delete node;
node = next;
- next = node->next;
- } while (node != first); // do-while since `node == first` for the first node
-
+ }
+ delete node;
first = nullptr;
}
@@ -36,7 +34,7 @@ void Tour::show() const
Node *node = first;
do {
- cout << node << " " << node->next << endl;
+ cout << *node << " " << *node->next << endl;
node = node->next;
} while (node != first); // do-while since `node == first` for the first node
}
diff --git a/labb3/tsp/src/Tour.h b/labb3/tsp/src/Tour.h
index bb5166b..7b47240 100644
--- a/labb3/tsp/src/Tour.h
+++ b/labb3/tsp/src/Tour.h
@@ -19,7 +19,7 @@ public:
int size() const; // return number of points on tour
double distance() const; // return total distance of tour
void insertNearest(Point p); // insert `p` using nearestNeighbour
- void insertSmallest(Point p); // insert `p` using insertSmallest
+ void insertSmallest(Point p); // insert `p` using smallestIncrease
private:
Node *first; // first node
diff --git a/labb3/tsp/src/tsp.cpp b/labb3/tsp/src/tsp.cpp
index 57de067..975e657 100644
--- a/labb3/tsp/src/tsp.cpp
+++ b/labb3/tsp/src/tsp.cpp
@@ -53,10 +53,11 @@ int main(int argc, char *argv[]) {
Point p(x, y);
tour.insertSmallest(p);
// uncomment the 4 lines below to animate
- // tour.draw(scene);
- // std::chrono::milliseconds dura(50);
- // std::this_thread::sleep_for(dura);
- // a.processEvents();
+ tour.draw(scene);
+ std::chrono::milliseconds dura(50);
+ std::this_thread::sleep_for(dura);
+ a.processEvents();
+ scene->clear();
}
input.close();
@@ -64,7 +65,7 @@ int main(int argc, char *argv[]) {
cout << "Tour distance: " << std::fixed << std::setprecision(4)
<< std::showpoint << tour.distance() << endl;
cout << "Number of points: " << tour.size() << endl;
- tour.show();
+ //tour.show();
// draw tour
tour.draw(scene);