Archive

Posts Tagged ‘circular list’

converting simple STL list to circular list

February 11, 2009 Leave a comment

/////////////////////////////////////////////////////////
//converting simple STL list to circular list
/////////////////////////////////////////////////////////
list<int>::iterator nextIter(list<int>::iterator i, list<int>::iterator beg,  list<int>::iterator end){
i++;
if(i == end){i = beg;}
return i;
}
/////////////////////////////////////////////////////////
list<int>::iterator prevIter(list<int>::iterator i, list<int>::iterator beg,  list<int>::iterator end){
if(i == beg){i = end; i–;}
else{i–;}
return i;
}
/////////////////////////////////////////////////////////
void printL(list<int> &L){
cout << endl;
list<int>::iterator i;
for(i=L.begin(); i != L.end(); ++i) cout << *i << ” “;
cout << endl;
}

Categories: C++, STL Tags: