Hey guys.

I need help on how to find the largest/smallest position in a set of vectors. Because I'm using vector<bool> type.. the elements in my vector are either 0's or 1's.. therefore what I need to do:

1. find out what position they are at (all the 1 values)
2. find the largest position of all the values = 1 (bool vector)
3. find the smallest position of all the values = 1 (bool vector)
4. find out if any integer is in the set of positions

I have no idea on how to do this :S any help or code would be appreciated.

Thanks :)

Recommended Answers

All 4 Replies

How about you loop through each element in your vector and determine of it's true or false. If it's true, store the position in a vector<int> positions for example. When you're done looping, your first occurrence of 'true' will be in positions.at(0) . Your last occurrence will be in positions.at(positions.size()-1)

Thanks, i'll work on it now :D

Okay there is a problem.. the positions are constantly updating to new values as expected.. but since the "positions" vector is an int type.. it stores old values as well.. and it will not update to the new position values.

How can I update these position values from my vector<bool> to vector<int>.. because it would somehow have to delete the old values in vector<int>positions and update the positions vector with new positions from the vector<bool> type..

Please help, this is really frustrating :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.