I have an array of [2,3,4,3,4,5,6,3] now I want to know how many 3's are there in an array. Is there any short cut to do it rather than going through the loop and checking each element?
- What do you mean by shortcut? performant way?Saeed Amiri– Saeed Amiri2012-05-01 15:09:08 +00:00Commented May 1, 2012 at 15:09
- Saeed's point is very valid. "short cut" by way of concise source code, or shortcut for performance? For performance, obviously you might get benefits from parallel searches in different parts of a very large array. But each thread still has to do element by element comparison. There are almost certainly faster assembly langauge commands than the naive compilation of a loop doing comparisons - your compiler might or might not use them - but there's nothing directly specifiable in C++.Tony Delroy– Tony Delroy2012-05-01 16:18:34 +00:00Commented May 1, 2012 at 16:18
- I mean in terms of no. of lines of code!Sadiksha Gautam– Sadiksha Gautam2012-05-01 16:26:49 +00:00Commented May 1, 2012 at 16:26
Add a comment |