Ok I want to be able to not only return when numbers finds a match but i want to know how many times they match. In the case below you will see that it will tell me "10 is a match of numbers" but if numbers; contained 10 , 10 , 10 how can I get it to tell me "there are 3 matches" or as of now tell me "there are 2 matches"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
std::vector<int> numbers; //Contains 10,20,10
//Search numbers for matches
it = std::adjacent_find (numbers.begin(), numbers.end());
//Tell me if they matched
std::cout << *it << " Is a match of numbers"'\n';
I think this is the easiest way of trying to find how many matches there are, also open to any other ideas!
Could you clarify further? Are you looking for the length of the continuous run of equal numbers in an otherwise unsorted sequence (e.g. "70, -1, 10, 10, 10, 20" gives '3') or for the length of a continuous run in a sorted sequence ("-1, 10, 10, 10, 20, 70" gives '3'), or for a total number of matches in an unsorted sequene ("10, -1, 70, 20, 10, 10" gives '3')?
Use of adjacent_find implies the first, but the comment in code ("10, 20, 10") implies the last
Sorry I was just using a basic example! numbers is sorted by size order so the vector would show 10,10,20 , all I want to know is how many duplicates there are inside the vector I sorted them in size order so I could use adjacent find but I am not sure if that is the best way? its working but it doesnt tell me how many duplicates it contains
Guys thanks, Cire that works perfectly , its exactly what I needed ! now I can continue with my code but I am going to be spending a while breaking down exactly how it works (really quite new to vectors+iterators) , thanks again really appreciate it :)