0000 0000 0001 1000 0010 0001 0011 1100 0100 0010 0101 0101 0110 1001 0111 1110 1000 0100 1001 0110 1010 1010 1011 0111 1100 0011 1101 1011 1110 1101 1111 1111
I have two vectors a and b of type std::vector<std::bitset<4> >
vector a --> 1st column
vector b --> 2nd column
I want to form cycles using these 2 vectors
a[0] == b[0] == 0000 -- > no need to form a cycle a[1] != b[1] --> cycle can be formed. cycle 'c' is formed as follows: c = {a[1]==0001,b[1]==1000,... then search for b[1] =1000 in `vector a` and add the corresponding value in b at that position like now b[1] =1000 is at a[8], hence b[8] = 0100 is added to the cycle c = {a[1]=0001,b[1]=1000,b[8]=0100,...} now b[8] = 0100 is at a[4], hence b[4] = 0010 is added to the cycle c= {a[1]=0001,b[1]=1000,b[8]=0100,b[4]=0010,..} now b[4] =0010 is at a[2], hence b[2] == 0001 but b[2] = 0001 == 1st element in cycle 'c' hence leave it and this completes the cycle.
The below code is where I create a vector v1 to form the cycle 'c' , push values into it, perform operations and return the vector or cycle c.
x=a.at(i), y=b.at(i)
example : x=a.at(1),y=b.at(1)
std::vector<std::bitset<4> > getvector(int x, int y,const std::vector<std::bitset<4> >& a,const std::vector<std::bitset<4> >& b ) {
std::vector<std::bitset<4>> resultvector;
resultvector.push_back(x);//push a.at(1) into r
resultvector.push_back(y);//push b.at(1) into r
while(resultvector.back()!=resultvector.front()) //run the loop until last element in vector r != first element in r and comes out when ==
{
//loop begin
int pos = find(a,y);
r.push_back(b.at(pos));
//loop end
}
return resultvector;
}
I want to know how to write this loop to perform the above operation.