By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,990 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,990 IT Pros & Developers. It's quick & easy.

Returning all locations of a specific repeated element in a vector/deque

P: 2
Dear All,

I am trying to use the STL-'find' function to find all the locations of a specific repeating element in an unsorted vector/deque. I want the original vector/deque to stay unsorted. It is my understanding from the text books that 'find' will only return the location of the first occurence of the element in question. Is there an existing STL function that I can use?

Any suggestions would be greatly be appreciated.

Cheers
Ernst
Jan 31 '08 #1
Share this Question
Share on Google+
3 Replies


gpraghuram
Expert 100+
P: 1,275
Dear All,

I am trying to use the STL-'find' function to find all the locations of a specific repeating element in an unsorted vector/deque. I want the original vector/deque to stay unsorted. It is my understanding from the text books that 'find' will only return the location of the first occurence of the element in question. Is there an existing STL function that I can use?

Any suggestions would be greatly be appreciated.

Cheers
Ernst
I dont think so that a function which suits your requirement exists.
My idea is you can use an iterator to traverse the vector/deque and then store all the matched positions tiil you reach the end of the vector/deque

Raghuram
Feb 1 '08 #2

P: 2
I dont think so that a function which suits your requirement exists.
My idea is you can use an iterator to traverse the vector/deque and then store all the matched positions tiil you reach the end of the vector/deque

Raghuram
Thanks Raghuram. That is what I suspected.
Feb 1 '08 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
It is my understanding from the text books that 'find' will only return the location of the first occurence
That's true. But it uses an iterator as the starting location. You can use the iterator from the first location to be the start point for the next find. Just advance it by 1.
Feb 1 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.