#include using namespace std; #include #include #include template class interval_map { friend void IntervalMapTest(); private: std::map m_map; public: // constructor associates whole range of K with val by inserting (K_min, val ) // into the map interval_map( V const& val) { m_map.insert(m_map.begin(),std::make_pair(std::numeric_limits::lowest (),val)); }; // Assign value val to interval [keyBegin, keyEnd). // Overwrite previous values in this interval. // Do not change values outside this interval. // Conforming to the C++ Standard Library conventions, the interval // includes keyBegin, but excludes keyEnd. // If !( keyBegin < keyEnd ), this designates an empty interval, // and assign must do nothing. void assign( K const& keyBegin, K const& keyEnd, const V& val ) { // SORRY I COULD NOT TEST THE CODE AS WAS BUSY WITH OFFICE WORK if (!( keyBegin < keyEnd )) return; bool InsertKeyBegin = true; bool InsertKeyEnd = true; V ValueAtkeyEnd; typename std::map::iterator p1 = m_map.lower_bound(keyBegin); typename std::map::iterator p2 = m_map.lower_bound(keyEnd); if ( p1 != m_map.begin() ) { p1--; } if ( p1->second == val ) { InsertKeyBegin = false; } if ( p2 != m_map.begin() ) { p2--; } if ( p2->second == val ) { InsertKeyEnd = false; } ValueAtkeyEnd = p2->second; p1++;p2++; m_map.erase(p1,p2); if(InsertKeyBegin == true) { p1 = m_map.find (keyBegin);
Thank you for interesting in our services. We are a non-profit group that run this website to share documents. We need your help to maintenance this website.