diff options
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 } |
