Hello,
I have some computer code which I want to speed up with STL. I was wondering if there is a faster implementation of the code presented.
I wish to delete all the elements in array1 which have matching elements in array2. array1 and array2 are not sorted, and I need
to preserve their orders after deletion.
vector<int> array1(1000), array2(20);
int array1_elements, array2_elements;
struct array_remove {
bool operator()(const int& rhs) const
{
return (rhs == -1);
}
k = array1_elements;
for(i = 1; i <= array1_elements; i++) {
for(j = 1; j <= array2_elements; j++) {
if(array1 == array2[j]) {
array1 = -1;
k--;
}
}
}
std::remove_if(array1.begin(), array1.begin() + array1_elements, array_remove());
array1_elements = k;
I was thinking of using 2 sorts and a while statement, but
I was wondering if STL could be used for a faster implementation.
Any comments appreciated.
Thankyou.