// File: ZoomTable.h // // by Prof. Richard Chang for Spring 2007 CMSC202 at UMBC. // Students may base Project 5 on this code. // #ifndef ZOOMTABLE_H #define ZOOMTABLE_H // The following constants are stored in the // dummy head and tail nodes in a row/col of // the ZoomTable. These out-of-bounds values // distinguish the dummy nodes from "real" nodes. // The MIN values go in the dummy heads, the MAX // values go in the dummy tails. // #define ROW_MIN -1 #define ROW_MAX num_rows #define COL_MIN -1 #define COL_MAX num_cols // forward class declarations class ZoomTable ; // The Node class is pretty much specified in the // project description for Project 3. // class Node { friend class ZoomTable ; public: // default constructor Node() ; // alternate constructor. // The default argument values allows a Node to // be created without assigning a row and col value yet. // Node(int data, int row=-1, int col=-1) ; void set(int data) ; // stores payload int get() const ; // retrieves payload int row() const ; // get location in ZoomTable int col() const ; // get location in ZoomTable private: int m_data; // the payload int m_row ; // location in ZoomTable int m_col ; // location in ZoomTable Node *up ; // pointers to next Node in direction Node *down ; Node *left ; Node *right ; }; class ZoomTable { public: // Constructors ZoomTable(); ZoomTable(int rows, int cols) ; // Copy Constructor ZoomTable(const ZoomTable& rhs) ; // Destructor ~ZoomTable(); // Assignment operator ZoomTable& operator=(const ZoomTable& rhs); // Insert & Delete functions Node *insert(int row, int col, int data); Node *find(int row, int col) const ; void remove(Node *ptr) ; bool remove(int row, int col); // Main method for using ZoomTables int at(int row, int col) const ; // Get row and col heads Node *FirstInRow(int row) const ; Node *FirstInCol(int col) const ; // Zooming Node *ZoomLeft(Node *ptr) const ; Node *ZoomRight(Node *ptr) const ; Node *ZoomUp(Node *ptr) const ; Node *ZoomDown(Node *ptr) const ; // Prints the entire ZoomTable void dump() const; // Returns the size of the list int rows() const; int cols() const; private: int num_rows ; int num_cols ; Node *row_heads ; // array of dummy heads, one for each row Node *row_tails ; // array of dummy tails, one for each row Node *col_heads ; // array of dummy heads, one for each column Node *col_tails ; // array of dummy tails, one for each column // Bunch of housekeeping functions // Check if ptr is pointing to a dummy head or tail. // If so, return NULL // Node *ValidatedPtr(Node * ptr) const ; // Set up dummy heads and tails. // void InitializeHeadsAndTails() ; // Delete everything // void clear() ; // Deep copy rhs to this object // void copy(const ZoomTable& rhs) ; // Either find an existing Node with given row and col coordinates // or find where to insert such a node. // Node *locate(int row, int col, Node * &row_pos, Node * &col_pos) const ; // Insert new node in the given positions. // void splice(Node *ptr, Node *row_pos, Node *col_pos) ; }; #endif