I need to write a frequency function in order that numbers don't repeat when output vector 3 and common elements unless it shows up in V1 and V2 twice. Such as V1: 1 9 3 -1 3 2 V2: 3 2 10 -8 -10 -5 3 So in common vectors it would be the following: 3 3 2
How would I write and implement a frequency function in my following code please.
cout<< "Elements that are in V2, but are not in V1: ";
for (int i=0; i<V2.size(); i++)
{
if( V2[i]!= V1[i])
cout<< V2[i] << " ";
}
cout<< endl<< endl << endl;
return different;
}
int main()
{
int size1;
int size2;
cout<< "How big do you want V1 to be? ";
cin>> size1;
cout<< "How big do you want V2 to be? ";
cin>> size2;
vector<int> V1(size1);
vector<int> V2(size2);
fill_vector(V1, V2);
output( V1, V2);
cout<< "Elements that are common to both vectors: ";
common_elements (V1,V2);
cout<< "Elements that are in V1, but not in V2: ";
not_in_the_other_vector(V1, V2);
cout << "Unique elements of V1 and V2: ";
unique(V1, V2);
//lists common elements of V1 and V2
vector<int> common_elements(vector<int> &V1, vector<int> &V2)
{
vector<int> common;
for (size_t i = 0; i < V1.size(); ++i)
{
if (find(V2.begin(), V2.end(), V1.at(i)) != V2.end())
{
common.push_back(V1.at(i));
}
}
return common;
}