bool insert(T t) {
		ContIter it = std::lower_bound(elements.begin(), elements.end(), t);
		if (it != elements.end() && t >= it->lb && t <= it->ub) {
			return false;
		}
		ContIter pr = it - 1;
		if (it != elements.begin() && pr->ub + 1 == t) {
			++pr->ub;
			if (it != elements.end() && pr->ub + 1 == it->lb) {
				pr->ub = it->ub;
				elements.erase(it);
			}
		}
		else if (it != elements.end() && it->lb == t + 1) {
			--it->lb;
			if (it != elements.begin() && pr->ub + 1 == it->lb) {
				pr->ub = it->ub;
				elements.erase(it);
			}
		}
		else {
			elements.insert(it, interval(t));
		}
		++_size;
		return true;
	}
	bool erase(T t) {
		ContIter it = std::lower_bound(elements.begin(), elements.end(), t);
		if (it == elements.end()) {
			return false;
		}
		if (it->ub < t || it->lb > t) {
			return false;
		}
		if (it->lb == t && it->ub == t) {
			elements.erase(it);
			--_size;
			return true;
		}
		if (it->ub == t) {
			--it->ub;
			--_size;
			return true;
		}
		if (it->lb == t) {
			++it->lb;
			--_size;
			return true;
		}
		if (it->lb < t && it->ub > t) {
			elements.insert(it + 1, interval(t + 1, it->ub));
			it->ub = t - 1;
			--_size;
			return true;
		}

		assert(false && "interval_vector.erase() should never reach this place...");
		return false;
	}
 void operator()(Cont& c, long count) {
     long cnt = count / 10;
     if (cnt > c.size()) {
         cout << "RemoveMiddle: not enough elements"
              << endl;
         return;
     }
     for (long i = 0; i < cnt; i++) {
         typename Cont::iterator it = c.begin();
         it++;
         c.erase(it);
     }
 }
		inline
		bool replace_key (Cont& c,
						  const typename Cont::key_type& old_key,
						  const typename Cont::key_type& new_key)
		{
			typename Cont::iterator pos;
			pos = c.find(old_key);
			if (pos != c.end()) {
				// insert new element with value of old element
				c.insert(typename Cont::value_type(new_key,
												   pos->second));
				// remove old element
				c.erase(pos);
				return true;
			}
			else {
				// key not found
				return false;
			}
		}
Example #5
0
void strategy1()
{
    int numElems;
    cin >> numElems;
    Cont container;

    for (int ii = 0; ii < numElems; ii++)
    {
        container.push_back(0);
        cin >> container.back();
    }
    for (int day = 0; ; day++)
    {
        list<ContIter> toDelete;
        ContIter iThis(container.begin());
        ContIter iPrev(iThis);
        iThis++;
        while (iThis != container.end())
        {
            if (*iThis > *iPrev)
            {
                toDelete.push_back(iThis);
            }
            iThis++;
            iPrev++;
        }
        if (toDelete.empty())
        {
            cout << day << endl;
            break;
        }
//        cout << "toDelete ";
 //       dump(toDelete);
        for (list<ContIter>::reverse_iterator iDel = toDelete.rbegin(); iDel != toDelete.rend(); iDel++)
        {
            container.erase(*iDel);
        }
 //       dump(container);
    } 
}
Example #6
0
inline void erase(Cont& cont, const T& val) {
	cont.erase(std::remove(cont.begin(), cont.end(), val), cont.end());
}
Example #7
0
	iterator erase(const_iterator i) {
		return container.erase(i);
	}
Example #8
0
void drop(Cont &cont, Pred pred) {
    cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end());
}
Example #9
0
void SortUnique(Cont & c, Less && less, Equals && equals)
{
  sort(c.begin(), c.end(), std::forward<Less>(less));
  c.erase(unique(c.begin(), c.end(), std::forward<Equals>(equals)), c.end());
}
Example #10
0
void SortUnique(Cont & c)
{
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());
}
Example #11
0
void EraseIf(Cont & c, Fn && fn)
{
  c.erase(remove_if(c.begin(), c.end(), std::forward<Fn>(fn)), c.end());
}