I was trying to locate vector a in vector b. So it's like if vector a is in vector b then return true else false. And vector a should be like {1,2,3} and b should like {4,1,2,3,5,5,7}. The output of this code is coming like true 1 and false 0. So my problem is I don't want 1 and 0 to show up in the output. Also I want to write this code in recursive form so could anyone help me with this problem?
bool x(vector<int>& a, vector<int> b)
{
vector<int> index ( b.size(),0 );
int counter = 0;
if ( a.size() <= b.size() ) {
for ( int i = 0; i < a.size(); i++ ) {
for ( int j = 0; j < b.size(); j++ ) {
if ( a[i]== b[j]) {
index[j] = 1;
}
}
}
for ( int i = 0; i < index.size(); i++ ) {
if ( index[i] == 1 ) {
for ( int j = i; j < index.size(); j++ ) {
if ( index[j] == 1 ) {
counter++;
}
}
if(counter == a.size()){
cout<<"true"<<endl;
return true;
break;
}
else{
counter = 0;
cout<<"false"<<endl;
return false;
// continue;
}
}
}
}
return 0;
}