Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

https://userpages.umbc.edu/~cmarron/cs341.s20/projects/proj2.shtml

1 answer below »
https://userpages.umbc.edu/~cmarron/cs341.s20/projects/proj2.shtml
Answered Same Day Feb 24, 2021

Solution

Aditya answered on Mar 02 2021
144 Votes

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_e
or;
using std::invalid_argument;
Macro for a two-argument min function
#define MIN(a, b) ((a) < (b) ? (a) : (b))
Macro for a two-argument min function
#define MAX(a, b) ((a) > (b) ? (a) : (b))
forward declarations
template class RMQList;
template class Node;
template ostream& operato
(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& operato
(ostream &sout, const Node &x);
private:
K _key;
V _value;
Node *_next;
};
Overloaded insertion operator for Node
template ostream& operato
(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 Operato
~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 cu
ent 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.
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here