I have a vector of vector (loops
) which contains integer values. Some inside vectors are duplicating but their element order is not the same. Now, I want to get a vector of vector without having any duplicate inner vectors.
here is an example for my vec of vec;
loops = ((9 18 26 11 9), (9 11 26 18 9),(9 18 25 16 9),(11 45 26 11),( 11 26 45 11),( 16 49 25 16),( 16 25 49 16),(18 9 11 26 18),( 18 9 16 25 18),( 25 16 49 25),( 26 11 45 26))
To identify whether any inner vector is a duplicate of another inner vector; I have developed a function IsDuplicate
. This tells me, (9 18 26 11 9) and (9 11 26 18 9)
are duplicates then I can delete the second or all other duplicates.
To remove duplicate vectors inside my vector of vector, I have implemented following codes.
Vector<vector<int> > loops;
Vector<vector<int> > ::iterator no1, no2;
Int setno1, setno2;
for (no1=loops.begin(), setno1=0; no1!=loops.end(); no1++, setno1++){
set1 = *no1;
for (no2=loops.begin()+setno1, setno2=setno1; no2!=loops.end(); setno2++){
set2 = *no2;
if (set2.IsDuplicate(set1)) loops.erase(loops.begin()+setno2);
else no2++;
}
}
it took very very long time and i thought my program is crasihing. so, Please help me to rectify this issue.
also, i tried with this. this works but i got a wrong answer. any help please.
01 int first=0; bool duplicates=false;
02 do {
03 set1 = loops[first];
04 for (no2=loops.begin()+1, setno2=1; no2!=loops.end(); setno2++){
05 set2 = *no2;
06 if (set2.IsPartOf(set1)){
07 loops.erase(loops.begin()+setno2);
08 duplicates = true;
09 }
10 else no2++;
11 }
12 first++;
13 } while(!duplicates);