diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-09-21 22:11:59 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-09-21 22:11:59 +0200 |
| commit | bd04af6c3509b8b4fe02c30c5c0487aea491a8a9 (patch) | |
| tree | d5b16c8c1603a278e1ce47e3f25c6805639509b4 /labb3/tsp/src/Tour.cpp | |
| parent | 245a34f1fad0e4fe2fb6401dc1d5352e4914b48a (diff) | |
| download | tddd86-bd04af6c3509b8b4fe02c30c5c0487aea491a8a9.tar.gz | |
Corrections l3 tsp
Diffstat (limited to 'labb3/tsp/src/Tour.cpp')
| -rw-r--r-- | labb3/tsp/src/Tour.cpp | 14 |
1 files changed, 6 insertions, 8 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 } |
