我目前正在尝试为列表编写一个循环。我的代码是:如何为列表编写for循环?
template<typename T>
void Bubblesorting(list<T> & mylist)
{
typename T::const_iterator it1;
typename T::const_iterator it2;
for(it1=mylist.begin();it1!=mylist.end();it1++)
for(it2=mylist.begin();it2!=mylist.end()-(it1-begin());it2++)
if((*(std::next(it2,1))<*it2)
swap((*(std::next(it2,1)),*it2);
cout << *it2 << ' ';
}
编译失败:
error C2958: the left parenthesis '(' was not matched correctly
能否请你帮我检测究竟哪里出了问题我怎么能写一个for循环列表的元素?
列表迭代器不是随机访问,因此'+'运算符不起作用,并且您正在传递对const容器的引用,同时试图在方法内对其进行变异。 – bobah