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 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 9 deletions(-) (limited to 'labb3/tiles/TileList.h') 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 -- cgit v1.2.1