replace duplicated element of vector by other element of another vector

Write your question here.
if i have to vectors like {3, 2, 4, 5, 1} and {1, 3, 2, 4, 5} and i need to generate new vector take range of one vector and the rest from the another one like ( if the range of first vector 2, 4, 5 and the rest from the another one ,so the final vector is {1, 2, 4, 5, 5})
but i need to prevent duplication of elements within the new vector and replace the duplicated element out of range from first vector {1, 2, 4, 5, 5} by the rest from 1 to 5 like {1, 2, 4, 5,3} . and this is my code but it failed.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>
int random(int b) { return std:: rand()%b;};
int main ()
{
std :: cout <<"---------------------------------------------------------------------------"<<"\n";
std:: srand(unsigned (std:: time(0)));

int position_1=0 , position_2 =0, x = 0, y = 0;
do {
x= (rand()%4+1);
y = (rand()%4 +1);
// std :: cout <<x <<"\t"<<y<<"\n";

} while ((x== 2 || x== 4) && (y == 2|| y == 4)||(x==y));
if (x<y)
{position_1=x;
position_2=y;}
else
{position_1=y;
position_2=x;}
std:: cout << "posi_1 = "<<position_1 <<"\t" << "posi_2 = "<<position_2<<"\n";

std :: vector<int>p1;
p1.push_back(3);
p1.push_back(2);
p1.push_back(4);
p1.push_back(5);
p1.push_back(1);
std :: vector<int>p2;
p2.push_back(1);
p2.push_back(3);
p2.push_back(2);
p2.push_back(4);
p2.push_back(5);
std::vector<int>:: iterator f1 = p2.begin()+position_1-1;
std::vector<int>:: iterator l1 = p2.begin()+position_2;
std :: vector <int>subchilderen_1 (f1,l1);

std::vector<int>:: iterator f2 = p1.begin();
std::vector<int>:: iterator l2 = p1.end();
std :: vector <int>childeren_1 (f2,l2);

childeren_1.erase(childeren_1.begin()+position_1-1,childeren_1.begin()+position_2);
childeren_1.insert(childeren_1.begin()+position_1-1,subchilderen_1.begin(),subchilderen_1.end());
std::vector<int>::iterator v6;
std::vector<int>::iterator v7;
std::vector<int>::iterator v8;
std::vector<int>::iterator v9;
std::vector<int>::iterator v10;
bool q= false;
if (position_1 == 1)
{
for(v8=childeren_1.begin()+position_2;v8 != childeren_1.end(); v8++)
{
do {
for(v9=childeren_1.begin()+position_1;v9 != childeren_1.begin()+position_2; v9++)
{
if (*v8 == *v9)
true;
else
false;
}
if (true)
*v8 = rand()%5+1;
}while (true);
}
}
else
{
for(v6=childeren_1.begin();v6 != childeren_1.begin()+position_1; v6++)
{
do {
for(v7=childeren_1.begin()+position_1;v7 != childeren_1.begin()+position_2; v7++)
{
if (*v6 == *v7)
true;
else
false;

}
if (true)
*v6 = rand()%5+1;
}while ( true);
}


//--------------------------------------------------------------------------

for(v8=childeren_1.begin()+position_2;v8 != childeren_1.end(); v8++)
{
do {
for(v9=childeren_1.begin()+position_1;v9 != childeren_1.begin()+position_2; v9++)
{
if (*v8 == *v9)
true;
else
false;
}
if (true)
*v6 = rand()%5+1;
}while (true);
}
}
for(v4=childeren_1.begin(); v4!= childeren_1.end();v4++)
{
std :: cout <<" "<<*v4;
}
std ::cout <<"\n";

}
Please, use the code tags (and intuitive indentation) when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

I'm not quite sure, what the formal description of the problem is.

There are two vectors, V1 and V2. Can they be of different length?

The result vector V3 (with possible duplicates) seems to be:
V3 = V2[0..x[ + V1[x..y[ + V2[y..end[

If V3[0..x[ contains values that also occur in V3[x..y[, then they are replaced with something?
If V3[y..end[ contains values that also occur in V3[0..y[, then they are replaced with something?
Topic archived. No new replies allowed.