// CMSC 341 - Spring 2020 - Project 2 #ifndef _RMQLIST_H #define _RMQLIST_H #include #include #include using std::swap; using std::ostream; using std::cout; using std::endl; using std::sqrt; using std::range_error; using std::invalid_argument; // Macro for a two-argument min function #define MIN(a, b) ((a) < (b) ? (a) : (b)) // forward declarations template class RMQList; template class Node; template ostream& operator<<(ostream &sout, const Node &x); // ********************************************* // Node - node class for the RMQList linked list // key and value are templated (types K and V) // ********************************************* template class Node { friend RMQList; public: Node(K key = K(), V value = V(), Node *next = nullptr) { _key = key; _value = value; _next = next; } friend ostream& operator<< (ostream &sout, const Node &x); private: K _key; V _value; Node *_next; }; // Overloaded insertion operator for Node template ostream& operator<<(ostream &sout, const Node &x) { sout << "Key: " << x._key << ", Value: " << x._value; return sout; } // ******************************************************* // RMQList - list container (linked list) with RMQ support // key and value are templated (types K and V) // ******************************************************* template class RMQList { public: // Create an empty RMQList object RMQList(); // Destructor, Copy Constructor, Assignment Operator ~RMQList(); RMQList(const RMQList &rhs); const RMQList& operator=(const RMQList &rhs); // In-line function. Returns the size (number of elements). int size() const { return _listSize; } // In-line function. Returns true if the list is empty; false // otherwise. bool empty() const { return _head == nullptr; } // Insert an element into the list; list must be kept in increasing // order by key; duplicate keys are not allowed, so return false if // there is already an entry with the specified key, true otherwise. // Should check if key > largest current key and, if so, append to // the end of the list without iteration. bool insert(const K& key, const V& value); // Remove an element from the list; return false if no element // exists with the specified key value, true otherwise bool remove(const K& key); // Update value for the element with given key; return false if // there is no element with the given key, true otherwise bool update(const K& key, const V& value); // RMQ Query for k1 to k2. Throws exceptions (see documentation). V query(const K& k1, const K& k2); // Dump the list entries void dumpList() const; // Dump the RMQ info and table. What gets dumped depends on which // RMQ method is used. void dumpTable() const; // Clear the data data strucures void clear(); private: Node *_head; Node *_tail; int _listSize; // ********************************** // Private variables for RMQ go here! // ********************************** // ******************************************* // Declarations for private functions go here! // ******************************************* }; template RMQList::RMQList() { } template RMQList::~RMQList() { } template RMQList::RMQList(const RMQList &rhs) { } template const RMQList& RMQList::operator=(const RMQList &rhs) { } template bool RMQList::insert(const K& key, const V& value) { } template bool RMQList::remove(const K& key) { } template bool RMQList::update(const K& key, const V& value) { } template V RMQList::query(const K& k1, const K& k2) { } template void RMQList::dumpList() const { } template void RMQList::dumpTable() const { } template void RMQList::clear() { } #endif