|
-
November 24th, 2006, 10:13 AM
#1
Count elements within bounds in 2D array
Hi,
I'm trying to count the number of elements that contain numbers that lie within two boundry conditions in a 2D array.
So, if I have my data:
i j
10 100
20 200
30 300
40 400
I want to know how many rows (20<=i<=40 && 100<=j<=300). In this case 2. The arrays are also many lines long.
I thought that this would be really easy to do in a language that seems as powerfula nd flexible as C++ but......
Any ideas. Cheers.
Will
-
November 24th, 2006, 10:25 AM
#2
Re: Count elements within bounds in 2D array
And what's the problem doing what you said?
Code:
//for each 2D number
if(20<=i<=40 && 100<=j<=300)
//value is within
else
//it's not
I think I don't undestand your problem!! Sorry!
Albert.
-
November 24th, 2006, 10:51 AM
#3
Re: Count elements within bounds in 2D array
 Originally Posted by AlbertGM
And what's the problem doing what you said?
Code:
//for each 2D number
if(20<=i<=40 && 100<=j<=300)
//value is within
else
//it's not
I think I don't undestand your problem!! Sorry!
Albert.
20<=i<=40 yields true whatever i is. It is interpreted as (20<=i)<=40
Same thing for 100<=j<=300
The correct condition is:
Code:
20<=i && i<=40 && 100<=j && j<=300
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
November 24th, 2006, 11:03 AM
#4
Re: Count elements within bounds in 2D array
SuperKoko, you are always correcting me. I think I won't do any any other post, because all of them have errors :-)
Thanks for your answers and for correct me. It could be because today I've lunch with wine :-)
Albert.
-
November 24th, 2006, 11:19 AM
#5
Re: Count elements within bounds in 2D array
 Originally Posted by AlbertGM
SuperKoko, you are always correcting me. I think I won't do any any other post, because all of them have errors :-)
Please, continue posting.
Doing errors in untested code is very usual. Personally, I can't write much code without any problem if I don't try to compile it.
With time, you'll do fewer errors on untested code.

 Originally Posted by AlbertGM
Thanks for your answers and for correct me. It could be because today I've lunch with wine :-)
It may be a factor. 
Personally, I do many more errors when I'm sleepy.
PS: I tried to send this message as a PM but AlbertGM blocked PMs in his account.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
November 24th, 2006, 11:36 AM
#6
Re: Count elements within bounds in 2D array
 Originally Posted by SuperKoko
Please, continue posting.
Of course I'll do. I'm learning a lot :-)
 Originally Posted by SuperKoko
PS: I tried to send this message as a PM but AlbertGM blocked PMs in his account.
What's that? How I blocked that? How Can I unlock it?
Albert.
-
November 24th, 2006, 02:18 PM
#7
Re: Count elements within bounds in 2D array
 Originally Posted by AlbertGM
How I blocked that?
I guess it is the default behavior.
 Originally Posted by AlbertGM
How Can I unlock it?
Go to the User CP page, click the User Options link, and then, activate "Enable Private Messaging", and finally, click "Save Changes".
This link should go to your user options page:
http://www.codeguru.com/forum/profil...do=editoptions
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|