+ 2
Speed up the code
What is the fastest way to compare elements in vector?Considering that vector contains 1k+ elements
3 Answers
+ 1
You could do something like this:
#include <algorithm>
template <class T>
static bool compareVectors(vector<T> a, vector<T> b)
{
std::sort(a.begin(), a.end());
std::sort(b.begin(), b.end());
return (a == b);
}
0
Thanks for the response. I think my question wasn't clear enough. I wanted to find the fastest way to compare elements in one vector with each other, if there are identical elements in the vector, return true
0
Mmh. Ok. Donât the FASTEST way⊠:)