使用我当前的方法我得到一个运行时错误,"列出iter而不是derefrencable"。 for循环看起来像:
for (iter = the_list.end(); iter != the_list.begin(); iter--)
{
if (assignment >= (*iter)){ // If the assignment being added is greater than assignment being pointed to in the list, add it after
// the assignment being pointed to
if (!(assignment == (*iter))) // If the assignment being added is not a duplicate, add it
{
iter++; // Increment the iterator to add the assignment to place after the one it was compared to
the_list.insert(iter, assignment); // Insert the assignment at the iterator's position
break;
}
}
}
答案 0 :(得分:6)
最直接的方法是使用反向迭代器:
for (iter = the_list.rbegin(); iter != the_list.rend(); ++iter)