-1

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 :)

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by scantraXx-
0

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)

Edited by Nick Evan: n/a

0

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 :(

Edited by scantraXx-: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.