Okay, my problem is to create a function that emulates the remove algorithm in <algorithm>.
so far this is what I have:
Code:
template<class X, class T>
void remove(X& b, X& e, T test){
while(b != e){
if(*b == test)
++b;
else{
X temp = b;
while ( temp != test ) ++temp;
swap(*b, *temp);
b = temp;
}
}
}
but it doesn't quite work...
Code:
vector<int> vec;
//input 5 1 5
vec.push_back(5);
vec.push_back(1);
vec.push_back(5);
remove(vec.begin(), vec.end(), 5);
printing vec gives me: 1 1 5
Also, the real remove function returns a iterator...but that shouldn't be too hard.
Can someone help me show me what my version is doing wrong?