From c7c7cf71500ffaef9b42abc5c2980889b08a6220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 22 Sep 2020 11:15:23 +0200 Subject: Comments --- labb3/tiles/TileList.h | 53 +++++++++++++++++++++++++++++++++++++++++--------- labb3/tsp/src/Tour.h | 47 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 83 insertions(+), 17 deletions(-) diff --git a/labb3/tiles/TileList.h b/labb3/tiles/TileList.h index 10cfdfb..3b5081f 100644 --- a/labb3/tiles/TileList.h +++ b/labb3/tiles/TileList.h @@ -12,15 +12,50 @@ class TileList { public: - TileList(); // allocate an empty tile list - ~TileList(); // deallocate the tile list - void addTile(Tile tile); // add a tile to the tile list, possibly reallocating - void drawAll(QGraphicsScene *scene) const; // draw all tiles to `scene` - int indexOfTopTile(int x, int y) const; // return index of top tile at (x, y) - void lower(int x, int y); // move the top tile at (x, y) to the bottom - void raise(int x, int y); // move the bottom tile at (x, y) to the top - void remove(int x, int y); // remove the top tile at (x, y) - void removeAll(int x, int y); // remove all tiles at (x, y) + /* + * Create and allocate an empty tile list. + */ + TileList(); + + /* + * Deallocate the tile list. + */ + ~TileList(); + + /* + * Add `tile` to the tile list, possibly reallocating. O(1) amortized. + */ + void addTile(Tile tile); + + /* + * Draw all tiles to `scene`. O(n). + */ + void drawAll(QGraphicsScene *scene) const; + + /* + * Return the index of the top tile at (x, y). O(n). + */ + int indexOfTopTile(int x, int y) const; + + /* + * Move the top tile at (x, y) to the bottom. O(n). + */ + void lower(int x, int y); + + /* + * Move the bottom tile at (x, y) to the top. O(n). + */ + void raise(int x, int y); + + /* + * Remove the top tile at (x, y). O(n). + */ + void remove(int x, int y); + + /* + * Remove all tiles at (x, y). O(n^2). + */ + void removeAll(int x, int y); private: static const int INITIAL_SIZE = 10; // the initial size diff --git a/labb3/tsp/src/Tour.h b/labb3/tsp/src/Tour.h index 7b47240..2a644b7 100644 --- a/labb3/tsp/src/Tour.h +++ b/labb3/tsp/src/Tour.h @@ -12,14 +12,45 @@ class Tour { public: - Tour(); // create an empty tour - ~Tour(); // free all nodes - void show() const; // print the tour to stdout - void draw(QGraphicsScene *scene) const; // draw the tour on `scene` - 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 smallestIncrease + /* + * Create an empty tour. + */ + Tour(); + + /* + * Free all nodes in the tour. + */ + ~Tour(); + + /* + * Print the tour to stdout. + */ + void show() const; + + /* + * Draw the tour to `scene`. + */ + void draw(QGraphicsScene *scene) const; + + /* + * Return the number of nodes in tour. + */ + int size() const; + + /* + * Return the total distance of the tour. + */ + double distance() const; + + /* + * Insert `p` using the "nearest neighbour" heuristic. + */ + void insertNearest(Point p); + + /* + * Insert `p` using the "smallest increase" heuristic. + */ + void insertSmallest(Point p); private: Node *first; // first node -- cgit v1.2.1