I have the following code
vector<Interval> insert(vector<Interval>& intervals, Interval newInterval)
{
vector<Interval> res;
vector<Interval>::iterator it;
for (it = intervals.begin(); it != intervals.end(); it++)
{
if (newInterval.start < (*it).start)
{
intervals.insert(it, newInterval);
break;
}
}
if (it == intervals.end()) //---->vector iterator incompatible
{
intervals.insert(it, newInterval);
}
}
I am getting an error of vector iterator incompatible at the statement
if (it == intervals.end()) //---->vector iterator incompatible
{
intervals.insert(it, newInterval);
}
Can anyone please clarify why this is happening and how I can fix this ?
Aucun commentaire:
Enregistrer un commentaire