C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

please help me on lower_bound && upper_bound

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue Dec 26, 2006 10:10 am    Post subject: please help me on lower_bound && upper_bound Reply with quote



I have a class board, like this:
struct board
{
int x1, x2, h;
int time1, time2;
void calculate_time();
void assign(int x1__,int x2__,int h__);
};

And I have n boards stored in an array called boards__[n], and I have
got the array sorted by board.h ascendantly.

I have a pair<int,int> t=pair<int,int>(x0,h0).

What I want to do is: to find the last board int boards__[n] which
satisfies this:
its h< h0,
and its x1<=t.first
and its x2>=t.second.

So, can I do it by upper_bound or lower_bound?
Which one do I have to use?
I tried for a moment and I couldn't find a way. Will you please help me
out?
Thanks!
Back to top
Salt_Peter
Guest





PostPosted: Tue Dec 26, 2006 10:10 am    Post subject: Re: please help me on lower_bound && upper_bound Reply with quote



could.net (AT) gmail (DOT) com wrote:
Quote:
I have a class board, like this:
struct board
{
int x1, x2, h;
int time1, time2;
void calculate_time();
void assign(int x1__,int x2__,int h__);
};

And I have n boards stored in an array called boards__[n], and I have
got the array sorted by board.h ascendantly.

I have a pair<int,int> t=pair<int,int>(x0,h0).

What I want to do is: to find the last board int boards__[n] which
satisfies this:
its h< h0,
and its x1<=t.first
and its x2>=t.second.

So, can I do it by upper_bound or lower_bound?
Which one do I have to use?
I tried for a moment and I couldn't find a way. Will you please help me
out?
Thanks!

Take a look at std::map. It inserts std::pair key/elements using a
programmeable order and already provides lower_bound and upper_bound
member functions.
http://www.sgi.com/tech/stl/Map.html
You also have std::multimap if you need duplicate pairs.
Back to top
Guest






PostPosted: Tue Dec 26, 2006 10:10 am    Post subject: Re: please help me on lower_bound && upper_bound Reply with quote



thank you,
but I'm not dealing with pair stuff.
I wrap the two numbers in a pair is just to pass is as a single param
into the algorithm.
It's also OK to put the two numbers in an arbitrary structure.

Salt_Peter wrote:
Quote:
could.net (AT) gmail (DOT) com wrote:
I have a class board, like this:
struct board
{
int x1, x2, h;
int time1, time2;
void calculate_time();
void assign(int x1__,int x2__,int h__);
};

And I have n boards stored in an array called boards__[n], and I have
got the array sorted by board.h ascendantly.

I have a pair<int,int> t=pair<int,int>(x0,h0).

What I want to do is: to find the last board int boards__[n] which
satisfies this:
its h< h0,
and its x1<=t.first
and its x2>=t.second.

So, can I do it by upper_bound or lower_bound?
Which one do I have to use?
I tried for a moment and I couldn't find a way. Will you please help me
out?
Thanks!

Take a look at std::map. It inserts std::pair key/elements using a
programmeable order and already provides lower_bound and upper_bound
member functions.
http://www.sgi.com/tech/stl/Map.html
You also have std::multimap if you need duplicate pairs.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.