Возможный дубликат:
Удаление из std::vector при выполнении для каждого?
Я пытаюсь реализовать окраску по вертикали в соответствии с этим алгоритмом;
/*
Given G=(V,E):
Compute Degree(v) for all v in V.
Set uncolored = V sorted in decreasing order of Degree(v).
set currentColor = 0.
while there are uncolored nodes:
   set A=first element of uncolored
   remove A from uncolored
   set Color(A) = currentColor
   set coloredWithCurrent = {A}
   for each v in uncolored:
      if v is not adjacent to anything in coloredWithCurrent:
         set Color(v)=currentColor.
         add v to currentColor.
         remove v from uncolored.
      end if
   end for
   currentColor = currentColor + 1.
end while
*/
Я не понимаю, добавьте v в currentColor. "но я предположил, что это означает, что currentColor соответствует v. Поэтому что такое" set"? В любом случае проблема заключается в стирании элемента в векторе при его повторении. Это код.
    vector<struct Uncolored> uc;
    vector<struct Colored> c;   
    int currentColor = 0;
    struct Colored A;
    struct Colored B;
    vector<struct Uncolored>::iterator it;
    vector<struct Uncolored>::iterator it2;
    vector<struct Colored>::iterator it3;
    for(it=uc.begin();it<uc.end();it++){
        A.id = (*it).id;        
        uc.erase(uc.begin());
        A.color = currentColor;
        c.push_back(A);
        for(it2=uc.begin();it2<uc.end();it2++) {
            it3=c.begin();
            while(it3 != c.end()) {
                if( adjacencyMatris[(*it2).id][(*it3).id] == 0 ) {
                    B.id = (*it2).id;       
                    it2 = uc.erase(it2);
                    B.color = currentColor;
                    c.push_back(B);
                }
                it3++;
            }
        }
        currentColor = currentColor + 1;
    }
Я думаю, что строка it2 = uc.erase(it2); уже используется, но дает ошибку времени выполнения.