Hi there,
As a newbie I'm trying to implement a sorting function in C++, using the list-class. However, running the code I get the error that the list iterator is not incrementable... However it seems very unlikely as it should be incrementable!
code:
void shuffle (list<int> &list1)
{
list<int> smaller;
list<int> larger;
if (list1.size() > 1)
{
list<int>::iterator it;
//int it;
int x = list1.front();
for (it = list1.begin(); it != list1.end(); it++)
{
if(*it <= x)
{
smaller.push_front(*it);
list1.pop_front();
}
else
{
larger.push_back(*it);
list1.pop_front();
}
shuffle (smaller);
shuffle (larger);
}
}
else
{
print(smaller);
print(larger);
//cout << "No sorting needed! The list still looks like: ";
//print(list1);
}
print(smaller);
print(larger);
}
I implemented this function just in de CPP file, under the main.
Does anyone has any suggestions?